Statalist


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

st: Foreach and macros


From   "Joao Ricardo F. Lima" <[email protected]>
To   [email protected]
Subject   st: Foreach and macros
Date   Mon, 20 Oct 2008 11:51:16 -0300

Dear Statalisters,

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.

Thanks for the help!

-- 
-------------------------------
Joao Ricardo Lima
Professor
UFPB-CCA-DCFS
+553138923914
-------------------------------

*
*   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