I have a panel dataset where panel_county_id
is the individual id of a county and year
is year (for two years - 2005 and 2009). I am trying to find the gdp per capita growth rate between the two years.
I used the following syntax, but the variables were all null.
bysort panel_county_id (year) : gen gdppc_r_2009 = (gdppc[2009] - gdppc[2005])/(gdppc[2005])
How can I fix the syntax?
Your subscripts are quite wrong. After sorting, the observations you want are just 1 and 2 for the first and second observations in each panel.
bysort panel_county_id (year) : gen gdppc_r_2009 = (gdppc[2] - gdppc[1])/gdppc[1]
It's not an error to use subscripts that don't correspond to observations in the data, but the result will be missing values (Stata doesn't use the term "null" here).