Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[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" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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 
n.j.cox@durham.ac.uk 

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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index