Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: Get list of non-omitted variables after a regression
From
Joe Canner <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: Get list of non-omitted variables after a regression
Date
Mon, 10 Mar 2014 14:08:56 +0000
I interpreted Ludovico's question to refer to variables omitted because of collinearity or perfect prediction, but I didn't have a chance at the time to test a solution. Building on Paul's solution, one would have to look for variables in the regression matrix that start with "o.". For example,
. sysuse auto, clear
. gen length1=length
. regress price displacement foreign weight length length1 // Purposely putting two identical variables in so that one will be omitted
. local n : colnames e(b)
. di "`n'"
. local n = regexr("`n'","o\.[a-zA-Z]+","") // remove any variables starting with "o."
. di "`n'"
Joe Canner
Johns Hopkins University School of Medicine
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Seed, Paul
Sent: Monday, March 10, 2014 9:47 AM
To: [email protected]
Subject: Re: st: Get list of non-omitted variables after a regression
The simplest solution is to get the column names off the regression matrix.
*********** Start Stata code ***************
sysuse auto, clear
stepwise , pe(0.05) : regress price mpg rep78 headroom trunk weight length turn displacement gear_ratio foreign
local n : colnames e(b)
di "`n'"
* If you want to lose the constant...
local c _cons
local n : list n-c
di "`n'"
* Note, I am using macro extended functions to avoid silent, automatic
* truncation of macros at 245 characters whenever "=" occurs.
*********** End Stata code ******************
Paul T Seed, Women's Health, KCL
> Date: Sat, 8 Mar 2014 16:30:49 -0600
> From: Scott Merryman <[email protected]>
> Subject: Re: st: Get list of non-omitted variables after a regression
>
> See - _rmcoll , forcedrop -
>
> Scott
>
>
> On Sat, Mar 8, 2014 at 3:38 PM, Ludovico Zaraga
> <[email protected]> wrote:
> > Hello,
> >
> > Is there a simple way of getting a list (in the form of a macro) of
> > non-omitted variables after running a regression in Stata? I am using
> > a very large number of variables, so I can't do this by hand.
> >
> > Thanks,
> >
> > Ludovico
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/