Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Anti-collapsing time series data


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Anti-collapsing time series data
Date   Mon, 2 May 2005 18:08:43 +0100

expand 5
bysort ID (period) : gen year = 1959 + _n 

Also, consider linear interpolation, etc. 

Nick 
n.j.cox@durham.ac.uk 

Johnathan Boysielal
 
> I have a cross-sectional time series data set and I would 
> like to convert 
> it to a data set of annual observations by assuming that the 
> variables 
> remained at the same level during each five year period. (I 
> would like to 
> eventually merge it with another data set)
> 
> I discovered the "expand" command but I am not quite sure how 
> to use it.
> 
> I have something that looks like:
> 
> ID      period  var1    year
> 1       1       205     .
> 1       2       220     .
> 
> and would like to do something like:
> 
> expand 5
> sort ID period
> by ID: replace year = 1960 in 1 if period==1
> by ID: replace year = year[_n-1] + 1 if missing(year)
> 
> in order to get
> 
> ID      period  var1    year
> 1       1       205     1960
> 1       1       205     1961
> 1       1       205     1962
> 1       1       205     1963
> 1       1       205     1964
> 1       2       220     1965
> 1       2       220     1966
> ...
> 1       1       339     1960
> 1       1       339     1961
> etc.
> 

*
*   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/



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