Hello Statalist members,
I want to calculate the difference between the last and first observations in my time series data. I am using Stata 16 for Mac. I have 25 years of data with one observation for each year for 2167 individuals which are nested within 55 groups. I ultimately want to create percent change over time. But first wanted to create a variable that calculates 2014 observation - 1990 observation.
I first tried the following code but it was definitely not the correct syntax.
gen = ((var if year==2014) - (var if year==1990))
Then I tried to use xtset id year and the times series operators but I believe this is only the difference between the last and previous observation ie. 1991-1990 or 1992-1991 or 1993-1992.
gen diff = D.var
label variable diff "Difference: 2014-1990
gen change = D.`var' / L.`var'
label variable change "Change: 2014-1990/1990"
Please share how to create a new variable that is the difference between the last and first observations.
Thank you for your time and insights.
Be well and safe.
Related Posts with Calculate Difference between Last and First Observation in Time Series Data
Model Selection for Categorical dataHi,
I have a trouble fitting a model for a categorical data. My dependent variable recorded by a t …
collapse variable in more than 1 way in one collapse commandIs it possible to collapse the same variable in more than 1 way in 1 collapse command (e.g., to get …
Recode date into consecutive days from first dateHi there,
I am trying to generate a new variable (called daynumber) that recodes a date (currently …
How to generate i*j by forvalues?If year=1,2,3,4; and prov=1,2,3,4,5,6,7. So how to calculate i*j, thanks a lot!
I run this,but it is…
xline and text on top of twoway area plotI use
Code:
twoway (area y1 y2 year)
to create a plot and want to include a dashed vertical line on…
Subscribe to:
Post Comments (Atom)
0 Response to Calculate Difference between Last and First Observation in Time Series Data
Post a Comment