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?
Matching Actions to YearsI have to different databases. Database 1 has executive actions in specific years, but this is not c…
preparing data for propensity score matchDear All, I want to analyze if the gain in public health insurance due to this policy (Medicaid exp…
Kaplan Meier survival description output - no median resulthi all, I am using Stat 16 on Mac. I am calculating Kaplan Meier survival curves for 2 groups of pat…
rename variablesI am poor at Stata coding. I would like to rename from "logind1-logind84" to " logcoefstandind101, l…
generate a value indicating how many time a situation happens before the specific dateHello everyone in the community! Sorry to have some problems with the same data again , thanks agai…
Subscribe to:
Post Comments (Atom)
0 Response to How can I create a lagged 4 year max variable?
Post a Comment