Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: local macro with if qualifier


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: Re: local macro with if qualifier
Date   Mon, 6 Apr 2009 20:53:19 +0200

<>

What exactly are those "d31b_`i'"? If they are variables, then the -if- qualifiers are evaluated for the first value only. This may be what you want, but experience shows that users are unaware of this more often than they actually want it. If you could give a description of your data and what you want to achieve, I am quite sure that you will soon get a much easier solution...


HTH
Martin
_______________________
----- Original Message ----- From: "Sabrina Carrossa" <[email protected]>
To: <[email protected]>
Sent: Monday, April 06, 2009 8:25 PM
Subject: st: local macro with if qualifier


Dear all,
how can i use a local macro with the if qualifier option?
Unfortunately, this code doesn't work:

local i=`i'+1 if d31b_`i'!=d31b_`y' & d31b_`i'==0 & `y'<3

Thank you in advance.

The full code is:

gen amico=0
local i=1
set trace on
forval y=2/3 {
   replace amico=`i' if d31b_`i'!=d31b_`y' & d31b_`i'==1 & `y'==3
   replace amico=`i' if d31b_`i'==d31b_`y' & d31b_`i'==1 &
d31c_`i'>d31c_`y' & `y'==3
   replace amico=`i' if d31b_`i'==d31b_`y' & d31b_`i'==1 &
d31c_`i'==d31c_`y' & d31d_`i'>d31d_`y' & `y'==3
   replace amico=`i' if d31b_`i'==d31b_`y' & d31b_`i'==1 &
d31c_`i'==d31c_`y' & d31d_`i'==d31d_`y' & `y'==3
   replace debug=1 if d31b_`i'==d31b_`y' & d31b_`i'==1 &
d31c_`i'==d31c_`y' & d31d_`i'==d31d_`y' & `y'==3

   replace amico=`y' if d31b_`i'!=d31b_`y' & d31b_`i'==0 & `y'==3
   replace amico=`y' if d31b_`i'==d31b_`y' & d31b_`i'==1 &
d31c_`i'<d31c_`y' & `y'==3
   replace amico=`y' if d31b_`i'==d31b_`y' & d31b_`i'==1 &
d31c_`i'==d31c_`y' & d31d_`i'<d31d_`y' & `y'==3
   replace amico=`y' if d31b_`i'==d31b_`y' & d31b_`i'==1 &
d31c_`i'==d31c_`y' & d31d_`i'==d31d_`y' & `y'==3

   local i=`i'+1 if d31b_`i'!=d31b_`y' & d31b_`i'==0 & `y'<3
   local i=`i'+1 if d31b_`i'==d31b_`y' & d31b_`i'==1 &
d31c_`i'<d31c_`y' & `y'<3
   local i=`i'+1 if d31b_`i'==d31b_`y' & d31b_`i'==1 &
d31c_`i'==d31c_`y' & d31d_`i'<d31d_`y' & `y'<3
}
set trace off
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index