Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: xline macro or scalars


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: xline macro or scalars
Date   Wed, 24 Sep 2003 15:31:25 +0100

Buzz Burhans
 
> I'm having trouble accomplishing the following:
> 
> In a dataset with multiple panels that is tsset, and I have 
> three event 
> variables containing integers in the same scale as the time 
> variable (days); for any given panel either 1, 2 or all 3 of these 
> variables may be 
> missing.  I have programmed a routine whereby I repeatedly 
> generate xtline 
> graphs to inspect these panels values, and would like to 
> use the 1,2, or 3 
> values ( if not missing) in the three event  variables as 
> xline() values in 
> those xtline graphs.  I have been trying to get the three 
> values into a 
> macro which I could use inside the  xline option, but have been 
> unsuccessful. Can anyone suggest how to capture three 
> values of three 
> variables in a single macro?  Or, alternatively, another 
> way to get the 
> xtline values I need in a manner that can be automated to 
> reflect the unique values for each panel?

Buzz later found another solution; 
nevertheless, a direct solution may be of interest. 

As I understand it, Buzz has something like this 

id 
time 
event1 
event2 
event3 

and for each panel -event1-, -event2-, 
-event3- contain the times of events 1 to 3
if and only if those events occur 

and (presumably) there is at least one 
other response variable. 

I'd try something like this: 

levels id, local(levels) 
foreach l of local levels { 
	// next line clears macro 
	local events 
	forval i = 1/3 { 
		su event`i' if id == `l', meanonly 
		if r(max) < . local events "`events'`r(max)' " 
	} 
	if "`events'" != "" { 
		xtline response if id == `l', ///
		subtitle(panel `l') xline(`events') 
	} 
	else xtline response if id == `l', subtitle(panel `l') 
	more 
} 

Nick 
[email protected] 

*
*   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