0

Hi I'm pretty sure my code is completely wrong. I'm try to run a macro that performs an event study when firms are included into a portfolio and then removed to measure the average change in the model coefficients. Here I've tried to look at just the inclusion. When I run the macro I get the errors:

Apparent symbolic reference I not resolved, The %DO statement is not valid in open code**. 

I suspect there must be some major flaws in here.

Any advise would be appreciated and if anyone could point to a good online guide that would also be fantastic.

%macro estudy(ds=var1,subgroup=evntdum);
%let evntdays=%eval(&end-&start+1); 

/date counter and split data and event periods/

data estper evntper;
merge &ds (drop=before) n&ds;
by firm evntdate;
if first.evntdate then relday=-before_sum - 1;
relday + 1;
if relday <-30 then output estper;
if &start <= relday <= &end then output evntper;
run;

/* model parameters in estimation period/take out firm. non port are weighted returns not in the portfolio. I exclude each firm for its inclusion event.*/

proc reg data=estper outest=mmparam (rename=(intercept=alpha port_ret=beta1         Non_port_ret=beta2)
keep=asx evntdate intercept asx200_ret non_asx200_ret) noprint;
by asx evntdate;
model var1(firm ret)= asx200_ret (non_asx200_ret-weighted_ret(var1));
quit;

proc reg data=evntper outest=afiparam (rename=(intercept=alpha port_ret=beta1     Non_port_ret=beta2);
keep=firm evntdate intercept port_ret non_prt_ret) noprint;
by firm evntdate;
model var1(firm ret)= (port_ret-weighted_ret(var1)) non_firm_ret;
quit;

run; 
%mend estudy;

Then calling the macro with:

/* one day stats */

%evntrun(dataset=libref.dset,portf=evntdum);
%do i=0 %to 0;
%let start=&i;
%let end=&i;
%estudy(ds=&dataset,subgroup=&portf)
%end;

/*multiday statistics */

%let start = -120;
%let start = 180;
%estudy(ds=&dataset,subgroup=&portf);
%mend evntrun;

/* run program */

%evntrun(ds=&dataset,subgroup=&portf);
Darko Kenda
  • 4,781
  • 1
  • 28
  • 31
Hamish
  • 35
  • 1
  • 7
  • You have no do loop in your code so hard to see how that error would be generated. Are you showing the full code? The UCLA tutorials on macros are quite good and easy to find via google. – Reeza Oct 01 '14 at 03:32
  • I just edited the post to include the rest of the code. I'll check out the UCLA stuff. Looks great so far. – Hamish Oct 01 '14 at 04:04

1 Answers1

2

The error messages about %do statement and &i not resolving are because you have forgotten the %MACRO statement and the start of the definition of %evntrun. It should be:

%macro evntrun(dataset=libref.dset,portf=evntdum) ;

There may be other issues as well. Would suggest making &start and &end parameters to %estudy.

Quentin
  • 5,960
  • 1
  • 13
  • 21
  • That got it to start running. I'm modifying some other code so not really sure what's going on. At least now I can start messing around with it. – Hamish Oct 01 '14 at 23:00
  • I'm getting the error that ds and subgroup aren't defined. Would this because &start and &end parameters aren't on %estudy? I thought I'm setting the start and end parameters in the second macro. – Hamish Oct 01 '14 at 23:13
  • You've passed them macro variables not actual values. If you haven't declared &dataset somewhere else it won't exist. My guess is you've used it somewhere else but its created as a local macro variable not a global macro variable. – Reeza Oct 03 '14 at 01:39
  • Your macro %evntrun has two parameters, named dataset and portf. – Quentin Oct 03 '14 at 12:54
  • Your macro %evntrun has two parameters, named dataset and portf. When you invoke it now, your code is %evntrun(ds=&dataset,subgroup=&portf). ds and subgroup are not parameters of %evntrun. This causes the error. You could change the macro invocation to be %evntrun(dataset=&dataset,portf=&portf) – Quentin Oct 03 '14 at 13:01