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
Problem with merging two datasetsHello, I have a problem with merging two datasets. My main dataset consists of trade data, with the…
Total days on medicine with multiple entries & overlapping datesHi, I am working on a database of medications taken by individuals which I need to summarise & …
Graphing MLR Predictions with Scatter of Data.I want to be able to graph my multiple linear regression predictions on the same graph as the scatte…
Industry Dummy VariablesI am conducting a cross-sectional study on UK firms and I've created an industry variable 'ind1' tha…
Shortcut to create the same graph for different specific unitsHi, I have two basic questions but I could not find an answer on my own. I need to create 40 differ…
Subscribe to:
Post Comments (Atom)
0 Response to Calculate Difference between Last and First Observation in Time Series Data
Post a Comment