How can I write equation with many dummies efficiently in proc model?

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

How can I write equation with many dummies efficiently in proc model?

I need to estimate a model with a lot of dummies (>50) with proc model ( I cannot really use proc glm or proc genmod, because it is actually a simultaneous equation model).

 

The parameters are defined as py_dmy1-py_dmy100 and the dummy variables are dmy1-dmy100. The equation will look like the following:

 

eq. y = - y_var + beta1*x1 + beta2 *x2 + py_dmy1*dmy1 + ....+ py_dmy100*dmy100;

 

eq.z= -z_var + gam1*x1 + gam2*x2 +pz_dmy1*dym1 + ... + pz_dmy100*dmy100;

 

The trouble is that the part "p_dmy1*dmy1+...+ p_dmy100*dmy100" is too long if I write it mannually. Is there a way to write it more efficiently?

 

 

What I tried is the following:

 

proc model data =xxxx;

     parameter beta1 beta2 y_dmy1-py_dmy100 gam1 gam2 pz_dmy1-pz_dmy100;

    array py_dmy_s {100} py_dmy1-py_dmy100;

   array pz_dmy_s{100} pz_dmy1-pz_dmy100;

    array dmy_s {100} dmy1-dmy100;

   dmy_part_y=0;

   dmy_part_z=0;

    do jj=1 to 100;

    dmy_part_y=dmy_part_y+py_dmy_s{jj}*dmy_s{jj};

     dmy_part_z=dmy_part_z+pz_dmy_s{jj}*dmy_s{jj};

end;

 

  eq.y= -y_var +beta1*x1 +beta2*x2 + dmy_part_y;

  eq.z= -z_var +gam1*x1 +gam2*x2 + dmy_part_z;

  fit y z /sur;

 

run;

 

However, it does not work.

 

Can you guys give me some suggestion or advice?

 

Thank you very much.


Accepted Solutions
Solution
‎02-19-2016 10:43 AM
Super User
Posts: 11,144

Re: How can I write equation with many dummies efficiently in proc model?

You may want to make sure that your parameter line is correct. You have y_dmy1-py_dmy100 where you may want py_dmy1-py_dmy100 

 

I can help build something that looks like: eq. y = - y_var + beta1*x1 + beta2 *x2 + py_dmy1*dmy1 + ....+ py_dmy100*dmy100;

 

%macro mydummy(start=, end=, stem1= , stem2=);
   %local str;
   %let str=;
   %do i = &start %to &end;
      %let str = &str + &stem1.&i * &stem2.&i;
   %end;

   &str
%mend;

%put %mydummy(start=1, end=10, stem1=py_dmy, stem2=dmy);

This takes "stem" or common part of your variables and concatenates a loop counter from the values you provide.

 

NOTE: the line with only &str INTENTIONALLY does not have a ; at the end. That is so the value of the macro resolves in line as generated program code.

Use in your equation would look like:

 

eq. y = - y_var + beta1*x1 + beta2 *x2  %mydummy(start=1,end=100,stem1=py_dmy, stem2=dmy) ;

 

Change the stems for the other variables.

Again, note there your equation does not want a + before the %mydummy macro call as the macro provides its own starting +.

View solution in original post


All Replies
Solution
‎02-19-2016 10:43 AM
Super User
Posts: 11,144

Re: How can I write equation with many dummies efficiently in proc model?

You may want to make sure that your parameter line is correct. You have y_dmy1-py_dmy100 where you may want py_dmy1-py_dmy100 

 

I can help build something that looks like: eq. y = - y_var + beta1*x1 + beta2 *x2 + py_dmy1*dmy1 + ....+ py_dmy100*dmy100;

 

%macro mydummy(start=, end=, stem1= , stem2=);
   %local str;
   %let str=;
   %do i = &start %to &end;
      %let str = &str + &stem1.&i * &stem2.&i;
   %end;

   &str
%mend;

%put %mydummy(start=1, end=10, stem1=py_dmy, stem2=dmy);

This takes "stem" or common part of your variables and concatenates a loop counter from the values you provide.

 

NOTE: the line with only &str INTENTIONALLY does not have a ; at the end. That is so the value of the macro resolves in line as generated program code.

Use in your equation would look like:

 

eq. y = - y_var + beta1*x1 + beta2 *x2  %mydummy(start=1,end=100,stem1=py_dmy, stem2=dmy) ;

 

Change the stems for the other variables.

Again, note there your equation does not want a + before the %mydummy macro call as the macro provides its own starting +.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 236 views
  • 0 likes
  • 2 in conversation