|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Expanding single observation data to create unbalanced panel data set-up
From |
Jeph Herrin <[email protected]> |
To |
[email protected] |
Subject |
Re: st: Expanding single observation data to create unbalanced panel data set-up |
Date |
Wed, 21 Jan 2009 11:50:22 -0500 |
Assume you have four variables -country-, -warid-, -start-, and -end-
which contain the country, an identifier for the war, the start year
and the end year.
Then if I understand your data and problem correctly
gen length=2004-start+1
expand length
bys country warid : gen year=start+_n-1
bys country year : egen war=max(inrange(year,start,end))
bys country year : keep if _n==1
should do it.
hope this helps,
Jeph
Geoffrey Wallace wrote:
I have a civil war data set that contains a single observation for each
war, including start year, end year, and other conflict-level variables
for all wars that were ongoing or began between 1988 and 2004. My
objective is to expand this data set into a panel format with separate
annual observations for both the war and post-war periods, while all
years before the war started are excluded. So for a war lasting
1990-1992, this means there would be no observations for 1988-1989, but
then observations for the war years 1990-1992 as well as postwar years
1993-2004.
A complicating factor is that some countries experience several separate
wars during this period, each of which has a unique id. I want to make
sure I don’t create duplicate observations for those cases, but rather
have a simple indicator variable with “1” when a country is experiencing
war and “0” for the post-war period.
My question is whether anyone can suggest a relatively efficient way for
producing such a data set.
I’ve thought of manually going through the data and including a variable
indicating the number of years for the relevant war and post-war period,
then using the –expand– command to create the larger data set, and then
somehow reformatting it afterward for indicate each relevant year for
the war and post-war periods. However, I was wondering if there was a
more straightforward way to do this.
Thanks for your consideration.
Geoff
-
Geoffrey Wallace
PhD Candidate
Department of Government
214 White Hall
Cornell University
Ithaca, NY 14853
*
* 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/