Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: cmissing for xtline


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: cmissing for xtline
Date   Mon, 26 May 2008 16:52:40 +0100

It's not clear to me why -cmissing()- is illegal with -xtline-. Even if
it were legal, it would do no good, as it is applied too late to do what
you want. The following illustrates some technique for a work-around: 

webuse grunfeld
replace invest = . if uniform() < 0.1
separate invest, by(company) veryshortlabel
foreach v of var invest1-invest10 {
	local plot `plot' line `v' year, cmissing(n) ||
}
`plot', ytitle(invest)

Nick
[email protected] 

Carlos Eduardo Hernandez Castillo

I have a panel data base, where the ID variable is "city" and the time
variable is "year". I have information of "est_sal_nat" for 1996, 1999,
2001 and 2006; and I would like to plot a "xtline est_sal_nat, overlay"
graph. However, data before 1999 is not comparable with data after 2001.
Therefore, I would like a break in 2000. I reckon that, if I were using
something like a twoway plot, I may create new obs filled with missings
and then use the cmissing(no) option
(http://www.stata.com/statalist/archive/2006-11/msg00882.html). However,
this option is not available for xtline. Therefore, this is what I get:

. xtset city year
       panel variable:  city (strongly balanced)
        time variable:  year, 1996 to 2006, but with gaps
                delta:  1 unit
. set obs 20
obs was 16, now 20
. replace year=2000 in 17/20
(4 real changes made)
. replace city=_n-16 in 17/20
(4 real changes made)
. xtline  est_sal_nat, overlay cmissing(n)
option cmissing() not allowed


So I had to create artificial cities:

. replace city=city+4 if anno>2000
(8 real changes made)
. xtline  est_sal_nat, overlay


But then I had to take care of fixing the lines and the legend of the
plot:

. xtline est_sal_nat, overlay scheme(s2mono) plot1opts(lpattern(solid))
plot5opts(lpattern(solid)) plot2opts(lpattern(dash))
plot6opts(lpattern(dash)) plot3opts(lpattern(shortdash))
plot7opts(lpattern(shortdash))  plot4opts(lpattern(longdash_dot))
plot8opts(lpattern(longdash_dot)) legend(order(1 2 3 4) rows(1))



Which is ok for 4 cities and a break, but would not be ok for more
cities or breaks; especially while working with loops. 

Can you imagine an easier way?
Is there a reason for not allowing cmissing with xtline?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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