Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How to get covariate names after OLS regression


From   Ulrich Kohler <kohler@wz-berlin.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to get covariate names after OLS regression
Date   Wed, 30 Jun 2004 12:32:36 +0200

Maoyong Fan wrote:
> 	First of all, I run a OLS regression.  The reg command automatically drop
> some variables which cause multicolinearity.
>
> 	Secondly, I want to use the covariates which OLS just used to run other
> regressions.
>
> I know e(depvar) gives the name of dependent variable.  But I can not find
> some command in Stata to give me the name list of dependent variables (not
> include the dropped variables).  Could you give me some hint?

The names of the independent variables are put as colnames/rownames in the 
result matrices e(b) and e(V), and can be extracted from there. However, 
these matrices also contain the names of the dropped variables. Fortunetelly 
it is easy to spot these matrices  for the dropped variables, as all entries 
for the dropped variables are zero. 

Here is one way to proceed:

--------------------------------------
sysuse auto 
reg mpg weight length weight turn 
matrix B = e(b)
local k = colsof(B)                   // See -help matrix functions-
forvalues i = 1/`k' {
   if el(B,1,`i') ~= 0 {              // See -help matrix functions-
	matrix b = B[1,`i'..`i']    // See -help matrix extraction-
          local name: colname(b)      // See -help matmacfunc-
	local names "`names' `name'"  
   }
}
di "`names'"
---------------------------------------

hope this helps
uli

-- 
kohler@wz-berlin.de
+49 (030) 25491-361


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



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index