Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: loop error

 From fernando andrade To statalist@hsphsun2.harvard.edu Subject st: loop error Date Thu, 20 Oct 2011 14:38:38 -0400

```Hi
i am trying to run a loop (see below) that would replace xi with yi
when xi is missing. I have a set of xi: x1.. xn, y: y1 ...yn
where y1 corresponds to x1 and so on... yn to xn

the syntax is:

local J : word count "a1cig_m a1alc_m a1mar_m a1coc_m a1pb_m a1tr_m
a1sti_m a1sb_m a1an_m a1ha_m a1in_m a1crk_m  a1he_m a1ex_m a1ste_m
a1la_m"

forval j = 1/`J'{
local x : word `j' of "a1cig_m a1alc_m a1mar_m a1coc_m a1pb_m a1tr_m
a1sti_m a1sb_m a1an_m a1ha_m a1in_m a1crk_m a1he_m a1ex_m a1ste_m
a1la_m"
local y : word `j' of "a1bmcig a1bmalc a1bmmar a1bmcoc a1bmpb a1bmtr
a1bmsti a1bmsb a1bman a1bmha a1bmin a1bmcrk a1bmhe a1bmex a1bmste
a1bmla"
replace `x' = `y' if `x' ==.
}

when i run  it i get an error that i could not figure out what exactly
is happening. Could anyone give me a hand please?

the error is : invalid 'a1bmalc' where a1bmalc is the second variable
in the y set the corresponded variable in the x set is a1alc_m

thank you
Fernando
*
*   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/
```