[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Michael Hanson <mshanson@mac.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Re: area between reference lines |

Date |
Mon, 10 Nov 2008 22:03:39 -0500 |

Best, Mike On Nov 10, 2008, at 8:53 AM, Steichen, Thomas J. wrote:

<<remailer munchie>>Try adding option -plotr(m(zero))- to your plot. This will removethe gap.Tom ----------------------------------- Thomas J. Steichen steicht@rjrt.com ----------------------------------- -----Original Message-----From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael HansonSent: Friday, November 07, 2008 6:10 PM To: statalist@hsphsun2.harvard.edu Subject: Re: st: Re: area between reference lines Martin: While this approach can be useful, the example you give also shows its main disadvantage: the lines from the -xline- option span the full height of the chart, but the shaded -area- leaves very unsightly gaps between the shaded range and the border (axis) of the graph. In my opinion, this is not suitable for publication-quality graphics. Changing -area- to start/end at the border (axis) of the graphs (or adding an option to do so) would be, I think, a useful addition to Stata. Robert: Kit Baum has written -nbercycles- to automate the plotting of time series against the recession intervals for the US determined by the NBER peak and trough dates. It uses -area- graphs as well, so it runs into the same problems as in Martin's example. An alternative is to "force" -xline- (or -tline-) into plotting a range of lines. The code below isn't pretty -- and I welcome suggestions to improve it -- but it does work (for me, at least). This would be SO MUCH EASIER if -tline- could accept a range to shade, rather than just individual dates -- such as -tline (1960m4/1961m12 1969m12/1970m11)-, etc. Here's hoping StataCorp will consider this request for a future update.... // START WITH NEXT LINE // Example time series plot with recession shading // Assumes monthly data from 1960 through 2008 // Recession peaks & troughs from <http://www.nber.org/cycles/> // Must have -freduse- installed: -ssc install freduse- // Load example datafreduse UNRATE, clear // Will overwrite any existing data -- savefirst!drop date gen date = mofd(daten) format date %tm tsset date // Define NBER recession dates for shading // Note: Your mail program may break or "wrap" these lines // Note: Must place each -local- command on a single line local rec1 "1960m4 1960m5 1960m6 1960m7 1960m8 1960m9 1960m10 1960m11 1960m12 1961m1 1961m2" local rec2 "1969m12 1970m1 1970m2 1970m3 1970m4 1970m5 1970m6 1970m7 1970m8 1970m9 1970m10 1970m11" local rec3 "1973m11 1973m12 1974m1 1974m2 1974m3 1974m4 1974m5 1974m6 1974m7 1974m8 1974m9 1974m10 1974m11 1974m12 1975m1 1975m2 1975m3" local rec4 "1980m1 1980m2 1980m3 1980m4 1980m5 1980m6" local rec5 "1981m7 1981m8 1981m9 1981m10 1981m11 1981m12 1982m11982m2 1982m3 1982m4 1982m5 1982m6 1982m7 1982m8 1982m9 1982m101982m11"local rec6 "1990m7 1990m8 1990m9 1990m10 1990m11 1990m12 1991m1 1991m2 1991m3" local rec7 "2001m3 2001m4 2001m5 2001m6 2001m7 2001m8 2001m9 2001m10 2001m11" // Plot series with recession shadingtsline UNRATE if tin(1960m1,2008m12), ylabel(, angle(h)) ttitle("") ///tlabel(1960m1(60)2008m12, format(%tmcY) labsize(*0.9)) /// tline(`rec1' `rec2' `rec3' `rec4' `rec5' `rec6' `rec7', lc(gs12)) // end of example // FINISH WITH PREVIOUS LINE A final note: depending on what you do with your graph (i.e. what format you convert it to for publication), you may notice some "banding" of the vertical lines. Changing the line width of some of the *interior* dates of the -tline()- command can address this concern. (Best not to change lines for the peak/trough dates, or they may spill over into adjacent dates.) I haven't noticed this problem when I go from Stata graphs -> PDF -> LaTeX on my Mac -- but some students working with certain combinations of Microsoft OS's, office suites, and file formats (WMF, EMF, etc.) have seen this, so YMMV. Hope this is helpful, Mike On Nov 5, 2008, at 6:24 PM, Martin Weiss wrote:Line for the server... ********** sysuse uslifeexp, clear *plain vanilla tw (line le year, xli(1970 1980)) (area le year if year>=1970 & year<=1980), name(first, replace) legend(off) *or quick and dirty tricks if you want color up the upper edge of the graph tempvar aux g `aux'=80 tw (line le year, xli(1970 1980)) (area `aux' year if year>=1970 & year<=1980), name(second, replace) legend(off) *let`s see both gr combine first second ********* HTH Martin _______________________ ----- Original Message ----- From: "Robert Duval" <rduval@gmail.com> To: <statalist@hsphsun2.harvard.edu> Sent: Thursday, November 06, 2008 12:07 AM Subject: st: area between reference linesDear all, Does anyone knows how to fill the background area between two (vertical) reference lines in a twoway line graph? The idea is to shade the background of a specific (vertical) region of the graph to indicate that during those years (x axis) the economy was in a recession. Any help will be greatly appreciated robert* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/CONFIDENTIALITY NOTE: This e-mail message, including anyattachment(s), contains information that may be confidential,protected by the attorney-client or other legal privileges, and/orproprietary non-public information. If you are not an intendedrecipient of this message or an authorized assistant to an intendedrecipient, please notify the sender by replying to this message andthen delete it from your system. Use, dissemination, distribution,or reproduction of this message and/or any of its attachments (ifany) by unintended recipients is not authorized and may be unlawful.* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**RE: st: Re: area between reference lines***From:*"Steichen, Thomas J." <SteichT@RJRT.com>

**References**:**st: area between reference lines***From:*"Robert Duval" <rduval@gmail.com>

**st: Re: area between reference lines***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**Re: st: Re: area between reference lines***From:*Michael Hanson <mshanson@mac.com>

**RE: st: Re: area between reference lines***From:*"Steichen, Thomas J." <SteichT@RJRT.com>

- Prev by Date:
**Re: st: insheet delimiter problem** - Next by Date:
**st: more fancy NP++ editor** - Previous by thread:
**RE: st: Re: area between reference lines** - Next by thread:
**RE: st: Re: area between reference lines** - Index(es):

© Copyright 1996–2021 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |