[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: how to generate lates nonmissing lagged value
> 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
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?
latest, London, 4 July 2003: George III says sorry...
* For searches and help try: