Bookmark and Share

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]

Re: st: Keep observations in panel data


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Keep observations in panel data
Date   Tue, 18 Jan 2011 16:32:57 +0000

Here is another way to tackle this that hinges on being able to pack
the history into a string variable:

 gen history = ""
 bysort id (year) : replace history = history[_n-1] + string(subsidy)
 by id : replace history = history[_N]
 by id : gen start = strpos(history, "100") == _n
 by id : keep if start == 1 | start[_n-1] == 1 | start[_n-2] == 1

Nick

On Tue, Jan 18, 2011 at 3:29 PM, Nick Cox <[email protected]> wrote:
> You're right. That was silly of me.
>
> A crude but I hope improved solution is
>
> bysort id (year) : keep if
> (subsidy == 1 & subsidy[_n+1] == 0 & subsidy[_n+2] == 0) |
> (subsidy == 0 & subsidy[_n-1] == 1 & subsidy[_n+1] == 0) |
> (subsidy == 0 & subsidy[_n-2] == 1 & subsidy[_n-1] == 0)
>
> Nick
>
> On Tue, Jan 18, 2011 at 3:19 PM, s <[email protected]> wrote:
>> Dear s or S:
>> This sounds like
>> bysort id (year) : keep if subsidy == 1 & subsidy[_n+1] == 0 &
>> subsidy[_n+2] == 0
>> Nick
>> P.S. as a native English speaker, frequent reviewer and Editor, I
>> advise firmly against the English usage "a panel data", which does not
>> qualify as standard. (It seems mildly viral recently, but I'm not
>> deflected by that.)
>>
>>
>> Dear Nick,
>>
>> Thanks for your help, but I am implementing your solution and it only keep
>> the information for the
>> year in which subsidy==1. I also need the information for the rest of the
>> years. In the example,
>> the data corresponding to firm 1 for the years 2001, 2002, 2003 and 2004.
>>
>> id year subsidy
>>  1 2000   0
>>  1 2001   0
>>  1 2002   1
>>  1 2003   0
>>  1 2004   0
>>  1 2005   1
>>  2 2000   0
>>  2 2001   0
>>  2 2002   1
>>  2 2003   1
>>  2 2004   0
>>  2 2005   1
>>  3 2000   1
>>  3 2001   1
>>  3 2002   1
>>
>> Sergio
>>
>> P.S. I will take note of your observation about panel data.

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index