Dear All,
First post.... I'm looking to run a piece of code which involves a foreach command. I want to fully automate this code which is as follows: -
Can anyone advise how I do this as I am getting tired of continually typing it into STATA. I've tried to run this using the Do Editor tool and get the following error....
"foreach command may not result from a macro expansion interactively or in do files"
Is there something that can be done to full automate me work?
The codes as follows: -
local y
local r2=0
. foreach var of local x {
3. regress FXY `var'
4 if( e(r2) > `r2'){
5 local r2=e(r2)
6. local y "regress FXY `var'"
7. }
8 }
. di "`y’”
. `y’
local a
local vif_1=0
foreach var of local x {
`y' `var'
vif
return list
if(r(vif_1)<=1.5){
local a `a’ `var'
}
}
di "`a’”
foreach var of local a {
`y' `var’
vif
}
First post.... I'm looking to run a piece of code which involves a foreach command. I want to fully automate this code which is as follows: -
Can anyone advise how I do this as I am getting tired of continually typing it into STATA. I've tried to run this using the Do Editor tool and get the following error....
"foreach command may not result from a macro expansion interactively or in do files"
Is there something that can be done to full automate me work?
The codes as follows: -
local y
local r2=0
. foreach var of local x {
3. regress FXY `var'
4 if( e(r2) > `r2'){
5 local r2=e(r2)
6. local y "regress FXY `var'"
7. }
8 }
. di "`y’”
. `y’
local a
local vif_1=0
foreach var of local x {
`y' `var'
vif
return list
if(r(vif_1)<=1.5){
local a `a’ `var'
}
}
di "`a’”
foreach var of local a {
`y' `var’
vif
}
Comment