[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: graphing and shading
> Hi everyone,
> I've got a quation regarding the new graphing facilities in STATA8.
> Lets say I've got some GDP data over time. Stata provides a means whereby
> demarcate a year using xline. Thus, I could show the great depression as
> area between two vertical lines:
> - twoway connected gdp time, xline(1929 1945)
> But lets say that I'd like to shade the area between two years (useful if
> want to have a bunch of intervals indicating time of recession. Is there a
> to do this in STATA?
> A similar question came up last month. Gerald Wright (email@example.com)
> came up with this example to show how it may be done:
> sysuse gnp96,clear
> sum gnp
> local max=`r(max)'
> gen c=`max' if date>q(1992q1)&date<q(2001q1)
> lab var c "Clinton Years"
> twoway (area c date, bcolor(gs15)) (line gnp date, clpattern(solid))
> Hope this helps,
Another way (and somewhat easier way) to produce the same graph as the above
is to use the -scatteri- command with the -recast- option. The -scatteri- command
allows you to plot points manually in the graph region, and the -recast- option allows
you to recast the points into an area plot. By finding the maximum value for the
y-axis, you could plot one point at the beginning of the date range in need and one
at the end. Recasting to an -area- plot will automatically include the area beneath
the plotted points. For example, using the same data as above:
twoway (scatteri 10000 `=q(1992q1)' 10000 `=q(2001q1)', bcolor(gs15) recast(area) ///
legend(on order(1 "Clinton Years" 2 "Real GNP"))) ///
(line gnp date, clpattern(solid)), xlabel(, format(%tq))
As you can see, you can also avoid creating macros by using Stata's in-line evaluation
feature. The expressions `=q(1992q1)' and `=q(2001q1)' get evaluated to 128 and 164,
respectively. So, I've told Stata to plot points at (128,10000) and (164,10000).
Then, the -recast(area)- option shaded the region below the two points with a bar color of gs15.
The only thing left to do after overlaying the -line- graph is to reformat the time series labels for
the x-axis using the -xlabel- option.
Hope this helps.
* For searches and help try: