Statalist


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

Re: st: local macro with if qualifier


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: local macro with if qualifier
Date   Mon, 06 Apr 2009 14:33:29 -0400


How about:

  local i=`i'+(d31b_`i'!=d31b_`y' & d31b_`i'==0 & `y'<3)

?

hth,
Jeph


Sabrina Carrossa wrote:
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