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
serial autocorrelation in panel dataHi STATA community I have a panel data for period 2012-2020, with #obs 1988 and #groups 223, I run …
Instrument for Industry Concentration that is uncorrelated with priceI have been trying to identify a good instrument for industry concentration that is uncorrelated wit…
Panel data simulationMy study is to compare panel data estimators in the case of common and heterogeneous structural brea…
generate event timeDear All, Suppose that I have daily trading data for many years. (A sample of two-year data is "here…
how to calculate the hhi index for a list variables? Code: * Example generated by -dataex-. For more info, type help dataex clear input float(pr1_durati…
Subscribe to:
Post Comments (Atom)
0 Response to Calculate Difference between Last and First Observation in Time Series Data
Post a Comment