Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- fixed effect regression with cluster by demeaning

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-23-2018 11:29 AM
(1966 views)

I am writing a macro to run fixed effect regressions with clustering using the demeaning method as normal procedures give memory errors. With my current code, I have to modify the macro everytime I run a different regression as the variables are different and I have to get the means of them. I would like to write a macro which can apply to any variables I input without changing the macro. My current macro is:

```
%macro FEregression(dep,indep,clusterVar,FE_var);
* To run with fixed effects use the method of subtracting off the mean for each date because the standard dummy variables approach needs too much memory;
proc sort data=panel; by &FE_var; run;
proc means data=panel print; by &FE_var; output out=means (drop=_TYPE_ _FREQ_)
mean(&dep)=m&dep mean(A)=mA mean(B)=mB mean(C)=mC mean(D)=mD ;
run;
data means; merge panel means; by &FE_var;
&dep=&dep-m&dep;
A=A-mA; B=B-mB;C=C-mC;D=D-mD;
run;
proc surveyreg data=means; class &FE_var; cluster &clusterVar; * Cluster by clusterVar;
model &dep = &indep / solution;
run; quit;
%mend;
%FEregression(Y, A B C D, , date)
```

So for this example, I am regressing Y on A B C D.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

So what you are asking is to replace in this code:

proc means data=panel print; by &FE_var; output out=means (drop=_TYPE_ _FREQ_) mean(&dep)=m&dep mean(A)=mA mean(B)=mB mean(C)=mC mean(D)=mD ; run; data means;

merge panel means;

by &FE_var; &dep=&dep-m&dep; A=A-mA;

B=B-mB;

C=C-mC;

D=D-mD; run;

The A B C D variables as needed from the value of &indep where that is a list of variables?

Or are A B C D a subset of the variables in &indep? If so, how do we know what the subset would be?

Things might get a lot simpler if you had a VAR statement on your Proc means like

Var &dep &indep;

and used the autoname option on out put instead of forcing use of the mA mB variables. mean(&dep &indep)= /autoname would append _mean to the name of each variable.

the data step could then become

data means; merge panel means; by &FE_var; &dep=&dep- &dep._mean; %do i= 1 %to %sysfunc(countw(&indep)); %let tvar= %scan(&indep,&i); &tvar = &tvar - &tvar._mean; %end; run;

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

So what you are asking is to replace in this code:

proc means data=panel print; by &FE_var; output out=means (drop=_TYPE_ _FREQ_) mean(&dep)=m&dep mean(A)=mA mean(B)=mB mean(C)=mC mean(D)=mD ; run; data means;

merge panel means;

by &FE_var; &dep=&dep-m&dep; A=A-mA;

B=B-mB;

C=C-mC;

D=D-mD; run;

The A B C D variables as needed from the value of &indep where that is a list of variables?

Or are A B C D a subset of the variables in &indep? If so, how do we know what the subset would be?

Things might get a lot simpler if you had a VAR statement on your Proc means like

Var &dep &indep;

and used the autoname option on out put instead of forcing use of the mA mB variables. mean(&dep &indep)= /autoname would append _mean to the name of each variable.

the data step could then become

data means; merge panel means; by &FE_var; &dep=&dep- &dep._mean; %do i= 1 %to %sysfunc(countw(&indep)); %let tvar= %scan(&indep,&i); &tvar = &tvar - &tvar._mean; %end; run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.