[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Data Expansion Question
David Lektzian <[email protected]> writes about expanding a
cross-sectional time-series dataset. He writes,
> This is the way the original data looks:
>
> Unique id duration count year [...]
> 1 4 1 1990 [...]
> 2 3 1 1995 [...]
>
> I want to expand the data to look like this:
>
> Unique id duration count year [...]
> 1 4 1 1990 [...]
> 1 4 2 1991 [...]
> 1 4 3 1992 [...]
> 1 4 4 1993 [...]
> 2 3 1 1995 [...]
> 2 3 2 1996 [...]
> 2 3 3 1997 [...]
Try the following:
1. Make above example:
. input caseid duration count year
. 1 4 1 1990
. 2 3 1 1995
. end
2. Solution:
. expand duration
. sort caseid
. by caseid: replace count = _n
. replace year = year + count - 1
. list
-- Bill
[email protected]
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/