0

I want to make a twoway bar graph that plots a number against a date.

I want to manipulate the length of the x-axis and the labels and ticks. I tried to enter the dates in different formats into the xscale() and the xlabel() options, but keep getting the following errors:

range() invalid - invalid numlist error

and

invalid label specifier

I tried entering the dates in different formats:

clear

input date number 
16743 116
16835   384
17034   152
17113   267
17191   939
17246   372
17265   443
17302   406
17498   210
end
format date %tdnn/dd/CCYY

twoway bar number date , ///
xscale(range(11/3/2005 (100) 11/28/2007)) ///
 xlabel(11/3/2005 1/25/2007  11/28/2007)

I also tried the following:

twoway bar number date , ///
 xlabel(mdy(11,3,2005) mdy(1,25,2007)   mdy(11,28,2007) , format(%tdnn/dd/CCYY))

How do I refer to dates in xscale() and xlabel()?

I want the dates to have the same format as the x-axis variable.

ZoeFrance
  • 3
  • 1
  • 3

1 Answers1

4

You need to evaluate the corresponding date function:

clear

input date number 
16743 116
16835   384
17034   152
17113   267
17191   939
17246   372
17265   443
17302   406
17498   210
end
format date %tdnn/dd/CCYY

twoway bar number date, xlabel(`=daily("11/3/2005", "MDY")'    ///
                               `=daily("1/25/2007", "MDY")'    ///
                               `=daily("11/28/2007", "MDY")',  ///
                                format(%tdnn/dd/CCYY)) 

This can be done on the fly as above or using a local macro.

  • @ZoeFrance Please also consider up-voting my answer with the upper arrow above the check-mark. This is how you reward volunteers on Stack Overflow for their time and ensure that they will help you again in the future. –  May 16 '19 at 22:56