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

st: RE: how to generate lates nonmissing lagged value


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: how to generate lates nonmissing lagged value
Date   Fri, 4 Jul 2003 19:24:27 +0100

[email protected]

> I have a panel dataset with missing values and for each 
> individual at each 
> time period I need to generate variable V1 which assumes 
> value of 1 if current 
> and latest nonmissing lagged value of another variable V2 
> =1 and is zero or 
> missing otheriwse.
> Could you, please, give me a hint on how to do this.

Panel data: I assume variables -id- and -time-, so 
the latest previous non-missing value of -v2- is 
given by 

gen prevv2 = . 

bysort id (time) : 
	replace prevv2 = 
		cond(v2[_n-1] < ., v2[_n-1], prevv2[_n-1]) 

Then you appear to have a double condition 

(a) current value of v2 is 1 
(b) latest nonmissing lagged value of v2 is 1 

which is made into an indicator by 

gen v1 = v2 == 1 & prevv2 == 1 

There is related background at 

How can I replace missing values with previous 
or following nonmissing values?
http://www.stata.com/support/faqs/data/missing.html

latest, London, 4 July 2003: George III says sorry... 

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