Please use informative titles.
I'd like to know a quicker way, but this may help.
It should give all the covariates not dropped.
Global is bad style; local is better; here done
as rclass result _and_ a local.
I have not programmed the omission of those
variables that you don't want: that is left
as an exercise.
*! NJC 1.0.0 6 Nov 2004
program covars, rclass
version 8
capture local Covars : colnames e(b)
if _rc error 301
tempname b
mat `b' = e(b)
tokenize `Covars'
local k = 0
forval j = 1/`= colsof(`b')' {
if "``j''" != "_cons" & `b'[1,`j'] != 0 {
local covars "`covars'``j'' "
local ++k
}
}
if `k' {
di as txt "{p}`covars'{p_end}"
return local covars "`covars'"
c_local covars "`covars'"
}
end
. sysuse auto, clear
(1978 Automobile Data)
. regress mpg weight for for
Source | SS df MS Number of obs = 74
-------------+------------------------------ F( 2, 71) = 69.75
Model | 1619.2877 2 809.643849 Prob > F = 0.0000
Residual | 824.171761 71 11.608053 R-squared = 0.6627
-------------+------------------------------ Adj R-squared = 0.6532
Total | 2443.45946 73 33.4720474 Root MSE = 3.4071
------------------------------------------------------------------------------
mpg | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
weight | -.0065879 .0006371 -10.34 0.000 -.0078583 -.0053175
foreign | -1.650029 1.075994 -1.53 0.130 -3.7955 .4954422
foreign | (dropped)
_cons | 41.6797 2.165547 19.25 0.000 37.36172 45.99768
------------------------------------------------------------------------------
. covars
weight foreign
. local want : subinstr local covars "weight" ""
. di "`want'"
foreign
Nick
[email protected]
Pradeep Kurukulasuriya
> I have a model with a number of variables, some of which are
> collinear and
> therefore get dropped when a regress command is executed. Is
> there a way of
> extracting a subset of the names of the variables for which
> stata produces
> estimates into a local or global macro ?
>
> For example:
>
> If I execute:
>
> Regress y v1 z2 z3 v4
>
> And stata estimates
>
> Y v1 z2 z3
>
> How can I get z2 and z3 into a macro which I can use in
> another proceedure?
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/