< >
Martin suggested
- bys id: g salesgrowth=(sales[_n]-sales[_n-1])/sales[_n-1]-
This works, but I spend some time every year when I lecture about
panel data explaining to students why it is a Very Bad Idea to do so.
bys id: g salesgrowth = D.sales/L.sales
or
bys id: g salesgrowth = log(D.sales)
is a much safer way to do this, as the time-series operators will
catch any issues with the time index (what if period 4 was not
recorded for a given firm?). It requires that the data be -xtset- or -
tsset-, and doing so will also catch some miscoding if the time index.
Best to have Stata look for such mistakes in the process of data
transformation. Very misleading results can be produced if you use
explicit subscripts and the observation is completely missing (not
Stata missing, but not recorded at all).
Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html
*
* 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/