Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AW: st: on construction of variables in Stata
From
[email protected]
To
[email protected]
Subject
AW: st: on construction of variables in Stata
Date
Mon, 28 Mar 2011 17:14:18 +0100 (BST)
Dear Nick,
thanks a lot! This was very helpful!
Best,
Rado
----- Ursprüngliche Mail ----
Von: Nick Cox <[email protected]>
An: [email protected]
Gesendet: Montag, den 28. März 2011, 9:17:46 Uhr
Betreff: Re: st: on construction of variables in Stata
If we knew these id-specific dates from a separate variable, this would be
gen VAR = date > specific
As it is, it seems you need
clonevar VAR2 = VAR
bysort id (date) : replace VAR2 = sum(VAR2)
as missings are ignored by -sum()-, and this sum is bumped up by 1
when you hit 1.
Another way to do it
bysort id (date) : replace VAR2 = VAR2[_n-1] if missing(VAR2)
replace VAR2 = 0 if missing(VAR2)
That approach is documented
FAQ . . . . . . . . . . . . . . . . . . . . . . . Replacing missing values
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
2/03 How can I replace missing values with previous or
following nonmissing values?
http://www.stata.com/support/faqs/data/missing.html
I do this on a clone in case I have misunderstood you.
Nick
On Mon, Mar 28, 2011 at 2:06 PM, <[email protected]> wrote:
> I have a large data-set sorted by id and date over a period of three years (at
> the daily frequency).
>
>
> For each panel defined by id, I need to build a variable that takes a value
of
> one at a specific date that is different for each id. Consequently, the
> variable (VAR) must take a value of 1 till end of the sample period and it
>must
> take a value of zero at any date before this specific day.
>
>
> Currently, VAR has values of 1 only assigned to the specific days for each id
> and missing observations elsewhere.
>
>
> Could you please let me know if I could ask stata with some command to fill in
> VAR with zeros preceding these specific days and to fill it in with ones
> afterwards (ie after the occurrence of the specific date).
*
* 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/