BookmarkSubscribeRSS Feed
HEB1
Calcite | Level 5

Hi- I am looking for a code that can match panel data with years and industry only for pre- period. My modal is DID  Y=post*mandatory +Fixed effects. 

Mandatory is a dummy =1 or 0 represents my control and treatment (treatment is 1). Post is a dummy equals 1 after event. 

This is a panel data with 37 firms as treatment (mandatory=1). 

I need to match on pre- period based on variables "before_after_event years" (that is all years between  (-1)-(-4)) and "SIC_2digit". 

the propensity should be run on variables "E", "leverage" and "AT". 

1. I try to find a code but didn't see anything that can work.

2.When  "before_after_event years" is >= o , I do not need to match anymore- how can I build my sample for that? the pre- should be match but the post does not? 

3. I prefer to do not loose treatment firms 

Best,

HB

 

3 REPLIES 3
smantha
Lapis Lazuli | Level 10

Can you post what code you tried and what did not work. As well as a sample of expected output.

HEB1
Calcite | Level 5
I have tried to run this one- but I can't even run it. I don't have an
output example.


%macro match_by_yr(inset=, outset=, startyear=, endyear=, matches=,
calip=, ctrlrestvar=, pscorevar=, treatvar=);




proc sql; drop table &outset; quit;





%do i=&startyear %to &endyear;


%put Year &i;


proc sql;


/* generate treated dataset for this firm-year */


create table _treat as


select unique_id as idT,


&pscorevar as pscoreT


from &inset


where yr = &i and &treatvar = 1;


/* generate non-treated dataset for this firm-year */


create table _nontreat as


select unique_id as idC,


&pscorevar as pscoreC


from &inset


where yr = &i and &treatvar = 0 and &ctrlrestvar=0;


quit;





proc sql noprint;


select count(*) into :obs_count from _treat;


quit;





proc sql noprint;


select count(*) into :obs_count2 from _nontreat;


quit;


%if (&obs_count ge 1) and (&obs_count2 ge 1) %then %do;





/* match */


%PSMatching(datatreatment= _treat,


datacontrol= _nontreat,


method= NN,


numberofcontrols= &matches,


caliper=&calip,


replacement= no,


out = _matches);








*if a firm, either control or treatment, is selected in a year, then it can
not be selected again in future years;

proc sql;


create table &inset


as select a.*, b.IdSelectedControl as
id_delec from &inset as a left join _matches as b

on a.unique_id=b.IdSelectedControl;


quit;





proc sql;


create table &inset


as select a.*, b.MatchedToTreatID as
id_delet from &inset as a left join _matches as b

on a.unique_id=b.MatchedToTreatID;


quit;





data &inset;


set &inset;


if not missing(id_delet) or not
missing(id_delec) then delete;

drop id_delet id_delec;


run;








/* Start the dataset if First firm-industry */


%if &i = 1 %then


%do;


data &outset;


set _matches;


run;


%end;


/* otherwise append new matches to the running dataset */


%else


%do;


data &outset;


set &outset _matches;


%end;


%end;


/* clean up temp datasets for next iteration */


proc sql;


drop table _matches;


quit;


%end;


%mend match_by_yr;





mklangley
Lapis Lazuli | Level 10

@HEB1  What were you trying to do with that code you posted? I do not see how it is related to your objective or the data you provided. It will be tricky to give a solution without details of what is not working in code you've tried, and an output example.

 

Also, when you post SAS code, use use the "little running man" button.

mklangley_1-1591902086298.png

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 739 views
  • 0 likes
  • 3 in conversation