Statalist


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

st: local macro with if qualifier


From   Sabrina Carrossa <carrossa@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: local macro with if qualifier
Date   Mon, 6 Apr 2009 20:25:09 +0200

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/



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