The sting in Joao's problem is from wanting a regression of each variable in turn on the others: once the response is selected, it must be removed from the list of potential predictors.
Try (I've changed the notation so that local macro y contains the name of the response)
local vars "read write rw"
foreach y of local vars {
local x : list vars - y
svy: regress `y' `x'
}
For more, see -help macrolists-.
Nick
[email protected]
Joao Ricardo F. Lima
I'm trying to test for collinearity in survey regression. I have many
variables. Then, I was thinking how to use foreach. Looking at UCLA
Stata FAQ, I can do:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear
generate rw = read*write
svyset [pw=socst], strata(ses)
svy: regress read write rw
svy: regress write read rw
svy: regress rw write read
I generated a local macro and used the foreach command. However, the
example below is wrong because I have the variable read in both sides
of regress...
local vars "read write rw"
foreach x of local vars {
svy: regress `x' `vars'
}
Survey: Linear regression
Number of strata = 3 Number of obs = 200
Number of PSUs = 200 Population size = 10481
Design df = 197
F( 0, 197) = .
Prob > F = .
R-squared = 1.0000
------------------------------------------------------------------------------
| Linearized
read | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
read | 1 1.05e-15 9.5e+14 0.000 1 1
write | 7.26e-15 9.17e-16 7.92 0.000 5.45e-15 9.07e-15
rw | -1.45e-16 1.83e-17 -7.93 0.000 -1.81e-16 -1.09e-16
_cons | -3.91e-13 5.18e-14 -7.55 0.000 -4.93e-13 -2.89e-13
------------------------------------------------------------------------------
(running regress on estimation sample)
I read Nick's columm on Stata Journal, they are very useful and clear,
but I still don´t know how to solve this problem.
*
* 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/