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]
st: RE: RE: panel data cross referencing bewtween variables in different time
From
"Nick Cox" <[email protected]>
To
<[email protected]>
Subject
st: RE: RE: panel data cross referencing bewtween variables in different time
Date
Sun, 7 Mar 2010 17:03:56 -0000
It's possible to imagine cases with this code in which a panel sum of 0
is ambiguous.
The protocol
bys ID : egen byte X3_ever_one = max(x3 == 1)
by ID : egen total_X1 = total(X1) if X3_ever_one
avoids that.
Nick
[email protected]
Martin Weiss
clear*
inp int(ID Year) byte(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
end
list, noo
bys ID: egen maxperid=max(X3==1)
by ID: egen totalX1=total(X1*maxperid)
l, noo sepby(ID)
MoZo
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.
*
* 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/