Bookmark and Share

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]

Re: st: Extend observations in dataset


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: Extend observations in dataset
Date   Tue, 28 Jan 2014 11:08:32 -0600

Here is one way:

clear
input number year other
77777  1975    9
22222  1972    8
11111  1999    5
end

expand 4 if number == 11111, gen(newvar)
replace year = year[_n-1] +1 if newvar == 1

expand 4 if newvar==0 & number == 11111, gen(newvar2)
gsort number year -newvar2
//assumes 11111 is the smallest number
bys number: replace year = year[_n+1] -_n if newvar2 == 1

sort number year
drop new*
replace other = . if year != 1999 & number == 11111
l

Scott
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index