Dear SAS community users,
I have an unbalanced panel data set with firm years. In that set, I have a dummy marking an event year (year when new stock is issued). I want to find the median of a variable (sale, for example) 3 years before the event year for each firm ID. Then I want to find the median of the same variable 5 years after the event year for each firm ID.
I'd appreciate any help here. Thank you in advance.
Regards,
Hinh
Do it in one step with correlated sub-queries:
proc sql;
create table medianSales as
select
firm,
( select median(sales)
from have
where firm=a.firm and year between a.year-3 and a.year-1 )
as medianSalesBefore,
( select median(sales)
from have
where firm=a.firm and year between a.year+1 and a.year+5 )
as medianSalesAfter
from have as a
where flag;
select * from medianSales;
quit;
If you have SAS 9.4 - median function not valid in PROC SQL in earlier versions.
It won't generate an error, but it won't be the metric you expect.
Thanks @Reeza. A good thing to know.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.