Ricardo Altamirano
Ricardo Altamirano

Reputation: 15198

Generate percent change between annual observations in Stata?

How do I use the gen or egen commands to generate the percent change between observations for different years in Stata? For example, I have observations for 1990 through 2010, each with a different value for expenditures, and I'm trying to generate a new observation with the percent change from 1990-1991, 1991-1992, etc.

Upvotes: 5

Views: 33863

Answers (1)

Fr.
Fr.

Reputation: 2885

// Here's an example with another measure of growth:

clear
set obs 100
gen year = _n + 1959
gen expenditure = _n^(1/3) + runiform()
line expenditure year, yti("Synthetic data example")

// From Statalist:

bys year: g expendituregrowth=100*(expenditure[_n]-expenditure[_n-1])/expenditure[_n-1]

// Also:

gen expenditure_gr = (expenditure/expenditure[_n-1] - 1)*100 // growth rate for expenditure
gen expenditure_bl = 100*expenditure/expenditure[1] // baseline growth rate for expenditure; base 100 = 1960

line expenditure_gr year, yti("Growth rate")
line expenditure_bl year, yti("Growth rate (base 100 = 1960)")

// The computation of expenditure_gr is what I think you are looking for.

// If your data are well-formed, use Stata with time series and get the growth rate easily:

tsset year, delta(1)
cap drop expenditure_gr
gen expenditure_gr = D.expenditure / 100*L.expenditure

Upvotes: 3

Related Questions