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
Need some help on a loopHello dears all. I merged two datasets. The first dataset contained the listing of households' memb…
Unable to read .dta file through do file - works fine otherwiseHello! I am working on a do file alongside a colleague but its commands will not load successfully …
ologit in favour of parsimoniousness despite violated parallel lines?Dear Statalists, I could use your input on the following 😊 My case: I am testing the influence of…
Unexpected coefficients in GMM sysHello everyone, I'm new with GMM, I'm using this estimator because I found it's the most suitable fo…
Transforming survey results to numerical codes appropiately (Encoding help)Stata and Stata Forum Beginner here. Situation: Using Limesurvey data for a health-related QOL stud…
Subscribe to:
Post Comments (Atom)
0 Response to Calculate Difference between Last and First Observation in Time Series Data
Post a Comment