The relevant column in my dataset are "gvkey" (a group id), datadate (ex. YYYYMMDD = 20100531), and revt.
The observation frequency is annual.
I want to to construct a rolling max of "revt" for the PREVIOUS 4 years for some "gvkey".
I don't want to hard code a window size of 5 because this would not handle missing values appropriately.
I'm very new the STATA so I'm not sure how this should be handled but I think SQL is the way to go.
For sake of clarity, I need something that is the functional equivalent in STATA to this code from SAS
proc sql;
create table want as select
a.gvkey,
a.datadate,
max(b.revt) as maxRevt
from
have as a inner join
have as b on a.gvkey=b.gvkey and
b.datadate between intnx("YEAR", a.datadate, -4) and a.datadate - 1
group by a.gvkey, a.datadate;
quit;
Related Posts with How can I create a lagged 4 year max variable?
Controlling numbers with esttabHi Stata community, I have several regressions that I would ideally put in one table, but there are…
January effect regressionHello Guys I have a question related to regression. I have a Data in which in the columns there are…
KMatch: Memory Management in Nearest-Neighbor Matching with TiesHi Everyone! Currently running Stata 16. I'm trying to do nearest neighbor matching with Kmatch usi…
graph of a dependent variable in specific years (panel data)Hi guys, i'm not very able to use stata. For my thesis, I have a panel data(1970-2017) for different…
Creating a time series dummy variableDear STATAlist community, I am looking for help in creating a dummy variable for a time series. Thi…
Subscribe to:
Post Comments (Atom)
0 Response to How can I create a lagged 4 year max variable?
Post a Comment