

The tline() option also understands that the x axis isĬomposed of dates and can be used to place lines at particular dates. graph twoway tsline high low, tlabel(01apr2001 01jul2001 01oct2001, format(%tdmd) ) Here we change the format of the date to be month and day. Option where we can supply in valid format that we would supply We can change the format of the display of the date variable using the format() graph twoway tsline high low, tlabel(01apr2001 01jul2001 01oct2001) Ttick(), tmlabel(), tmtick(), and tscale(), seeĭetails. Other options that can be used in a similar way include For example, say that we wanted the x axis to be labeled Understand that the x axis is a date variable and are much easier to In addition to these benefits, there are options we can use that Next, note that the labels for the xĪxis are labeled much better with more logical values having been chosen. This is because Stata knew, from the tsset command, what the time Note that we did not need to specify date in the command. Now we can use graph twoway tsline to graph the data.

Time variable: date, 02jan2001 to 31dec2001, but with gaps To tell Stata that the variable date represents time and that its Graph twoway line we can use graph twoway tsline which is specifically designed for making line graphs where the Labeling the x axis since these are date values. Also, it could be difficult to change the values Properly labeled with the dates, but the selection of the values labeling thisĪxis could be better. We could use the graph twoway line command to graph the high and low closing price for the year, as shown below. High and low trading price for a given day and date which is a date This file has variables like high and low that represents the This data file contains data for all of the trading days in 2001. I would like to remove this.This FAQ shows examples of graphing data where the x axis represents dates.įor these examples, we will use the sp500 dataįile that comes with Stata and we can use it via the sysuse command. *A second, minor question is that I do not understand why the x-axis gets an elipsis (.) when I add the scatteri plot. I have tried adding axis(2) to the text box as an additional argument, but this option is apparently not allowed. It seems better to be able to attach the text to the line using the second y-axis gridpoints. Of course, I could manually determine this value for the histogram (as I did in this example), but I plan to create a set of these graphs via a loop, such that there are a dozen or so panels. The corresponding lines would instead be: text(1 `median' `"median = $`=string(`median',"%6.2f")'"', /// Instead of "0.08" which gets my text into the correct location, I would like to use "1", as this is the maximum value of the second y-axis. This is the reason I used the second y-axis in the first place. This produces the desired graph (for the most part*):Īt issue is that I do not know the height of the histogram beforehand. Scatteri 0 `median' 1 `median', recast(line) yaxis(2) /// Twoway hist mpg, start(10) width(5) || /// Here is an example of my issue: sysuse auto regression models) and then apply coefplot to these estimation sets to draw a plot. However, I cannot seem to add text to this line using the second y-axis coordinates (it instead uses the first y-axis coordinates, even though the object it is labeling is on the second y-axis). The basic procedure is to compute one or more sets of estimates (e.g. To fix this, I am using scatteri with coordinates.īecause I do not know the height of the histogram beforehand, I set the scatteri plot to use a separate y-axis, which I have hidden. I cannot use xline() because the line falls behind the histogram, rather than on top of it. I have a plot of a histogram, to which I would like to add the median.
