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: panel data cross referencing bewtween variables in different time


From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: panel data cross referencing bewtween variables in different time
Date   Sat, 6 Mar 2010 12:33:11 -0600

For data processing purposes, you can use something like

bysort ID (year) : gen sumX1condX3 = sum(X1) if
inlist(1,X3[1],X3[2],X3[3],X3[4],X3[5])
* sumX1condX3 contains the running sum for the relevant panels
bysort ID (year) : replace sumX1condX3 = sumX1condX3[_N]
* sumX1condX3 now contains the overall sum for the relevant panels

Not that this is very elegant, but that is A way to do it.

On Sat, Mar 6, 2010 at 12:24 PM, MoZo <[email protected]> wrote:

> I have a panel dataset which was set up as follow:
>
> ID      Year    X1      X2      X3
> 111   1990  89  21      0
> 111     1991    29      53      0
> 111     1992    87      76      1
> 111     1993    87      98      1
> 111     1994    45      88      0
> 222     1990    98      88      0
> 222     1991    98      44      0
> 222     1992    45      71      0
> .
> .
> .
> .
> 999     1990    76      98      0
> 999     1991    54      43      0
> 999     1992    65      32      0
> 999     1993    65      87      1
> 999     1994    76      32      0
>
> I want to do simple calculation referencing to one variable X3. For
> example,
> sum X1 for ID (panel) if the panel's X3=1 in ANY year. I can't find a
> command I can make reference to a variable that may occur any time. For
> example, in this data sample, I want to all X1 for all ID whose X3 is 1 in
> ANY year.
> Thank you in advance.
>
> Mike
>
> *
> *   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/
>



-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.

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