<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: fixed effect regression with cluster by demeaning in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/fixed-effect-regression-with-cluster-by-demeaning/m-p/456610#M23832</link>
    <description>&lt;P&gt;yes. that is correct, so that I dont have to change those steps everytime I run a different regression. So A B C D would be all the independent variables in the list &amp;amp;indep. Essentially, what I would like to do is to simply regress a new regression, say Z = M N O P Q by running %FEregression(Z, M N O P Q, clusterVar,date). To do this using my current method, I would have to rewrite the PROC MEANS and DATA step in my macro&lt;/P&gt;</description>
    <pubDate>Mon, 23 Apr 2018 17:38:19 GMT</pubDate>
    <dc:creator>somebody</dc:creator>
    <dc:date>2018-04-23T17:38:19Z</dc:date>
    <item>
      <title>fixed effect regression with cluster by demeaning</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/fixed-effect-regression-with-cluster-by-demeaning/m-p/456559#M23829</link>
      <description>&lt;P&gt;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:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%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 &amp;amp;FE_var; run;
	      proc means data=panel print; by &amp;amp;FE_var; output out=means (drop=_TYPE_ _FREQ_) 
	            mean(&amp;amp;dep)=m&amp;amp;dep mean(A)=mA mean(B)=mB mean(C)=mC mean(D)=mD ; 
	      run;
	    	data means; merge panel means; by &amp;amp;FE_var; 
				&amp;amp;dep=&amp;amp;dep-m&amp;amp;dep;
				A=A-mA; B=B-mB;C=C-mC;D=D-mD;	
			run;
            proc surveyreg data=means; class &amp;amp;FE_var; cluster &amp;amp;clusterVar; * Cluster by clusterVar;
                  model &amp;amp;dep = &amp;amp;indep  / solution; 
            run; quit;
%mend;

%FEregression(Y, A B C D, , date)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So for this example, I am regressing Y on A B C D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 15:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/fixed-effect-regression-with-cluster-by-demeaning/m-p/456559#M23829</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-04-23T15:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: fixed effect regression with cluster by demeaning</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/fixed-effect-regression-with-cluster-by-demeaning/m-p/456608#M23831</link>
      <description>&lt;P&gt;So what you are asking is to replace in this code:&lt;/P&gt;
&lt;PRE&gt;proc means data=panel print; 
  by &amp;amp;FE_var; 
  output out=means (drop=_TYPE_ _FREQ_) 
   mean(&amp;amp;dep)=m&amp;amp;dep mean(A)=mA mean(B)=mB mean(C)=mC mean(D)=mD ;  
run;

data means; &lt;BR /&gt;  merge panel means; &lt;BR /&gt;  by &amp;amp;FE_var; 
  &amp;amp;dep=&amp;amp;dep-m&amp;amp;dep;
  A=A-mA; &lt;BR /&gt;  B=B-mB;&lt;BR /&gt;  C=C-mC;&lt;BR /&gt;  D=D-mD;	
run;
&lt;/PRE&gt;
&lt;P&gt;The A B C D variables as needed from the value of &amp;amp;indep where that is a list of variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Or are A B C D a subset of the variables in &amp;amp;indep? If so, how do we know what the subset would be?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Things might get a lot simpler if you had a VAR statement on your Proc means like&lt;/P&gt;
&lt;P&gt;Var &amp;amp;dep &amp;amp;indep;&lt;/P&gt;
&lt;P&gt;and used the autoname option on out put instead of forcing use of the mA mB variables. mean(&amp;amp;dep &amp;amp;indep)= /autoname would append _mean to the name of each variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the data step could then become&lt;/P&gt;
&lt;PRE&gt;data means; 
  merge panel means; 
  by &amp;amp;FE_var; 
  &amp;amp;dep=&amp;amp;dep- &amp;amp;dep._mean;
  %do i= 1 %to %sysfunc(countw(&amp;amp;indep));
   %let tvar= %scan(&amp;amp;indep,&amp;amp;i);
   &amp;amp;tvar = &amp;amp;tvar - &amp;amp;tvar._mean;
  %end;
 run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Apr 2018 17:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/fixed-effect-regression-with-cluster-by-demeaning/m-p/456608#M23831</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-23T17:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: fixed effect regression with cluster by demeaning</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/fixed-effect-regression-with-cluster-by-demeaning/m-p/456610#M23832</link>
      <description>&lt;P&gt;yes. that is correct, so that I dont have to change those steps everytime I run a different regression. So A B C D would be all the independent variables in the list &amp;amp;indep. Essentially, what I would like to do is to simply regress a new regression, say Z = M N O P Q by running %FEregression(Z, M N O P Q, clusterVar,date). To do this using my current method, I would have to rewrite the PROC MEANS and DATA step in my macro&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 17:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/fixed-effect-regression-with-cluster-by-demeaning/m-p/456610#M23832</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2018-04-23T17:38:19Z</dc:date>
    </item>
  </channel>
</rss>

