Hi all!
Long time reader, first time poster here.
I have a dataset where each row is a state * timeframe. Some rows contain partial years (e.g., 1/1/09-7/23/09) and some contain multiple years (e.g., 7/24/09-12/31/11; see "what I have" in below screenshot). I would like to reformat the data so that there is one row per state per year (see "what I want").
So basically, I need to: (1) figure out when two or more rows make up a single year, and then combine them, averaging out the mw variable; and (2) figure out when a row contains multiple years, break the multi-year rows into separate rows of partial years, and then combine those partial years to form a single full year, again averaging out the mw variable.
This is how it would go, I think:

(I set this up in Excel, but I obviously want to do it in Stata.)
I honestly can't even wrap my head around how I'd get started doing this with code. I could do it by hand in Excel, but there are ~500 rows, so I'd rather not!
Does anyone have any thoughts??
Long time reader, first time poster here.
I have a dataset where each row is a state * timeframe. Some rows contain partial years (e.g., 1/1/09-7/23/09) and some contain multiple years (e.g., 7/24/09-12/31/11; see "what I have" in below screenshot). I would like to reformat the data so that there is one row per state per year (see "what I want").
So basically, I need to: (1) figure out when two or more rows make up a single year, and then combine them, averaging out the mw variable; and (2) figure out when a row contains multiple years, break the multi-year rows into separate rows of partial years, and then combine those partial years to form a single full year, again averaging out the mw variable.
This is how it would go, I think:
(I set this up in Excel, but I obviously want to do it in Stata.)
I honestly can't even wrap my head around how I'd get started doing this with code. I could do it by hand in Excel, but there are ~500 rows, so I'd rather not!
Does anyone have any thoughts??
Comment