Bookmark and Share

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   Ludovico Zaraga <[email protected]>
To   statalist <[email protected]>
Subject   Re: st: Get list of non-omitted variables after a regression
Date   Mon, 10 Mar 2014 10:57:30 -0500

Thanks, that works for what I have to do!

On 10 March 2014 09:34, Joe Canner <[email protected]> wrote:
> Sorry, my solution only allows for variable names with alphabetic characters.  Since we don't have to make any assumptions about the validity of the characters following the "o." in a list of variable names, we can do the following:
>
> . local n = regexr("`n'","o\..+","")
>
> (For those trying to learn about regular expressions: the "\." tells the function to look for a literal period and the ".+" tells the function to look for one or more characters after the "o.")
>
> Note: While testing this solution on categorical variables omitted because of perfect prediction in a logistic regression, I found that the problem becomes even more complicated.  For example:
>
> . sysuse auto, clear
> . // Generate a categorical variable where one strata perfectly predicts the outcome
> . gen x=recode(_n,25,50,75)
> . replace x=foreign if x==50
> . logistic foreign price x   // Silly example
> . local n : colnames e(b)
> . di "`n'"
>
> // Output is: price 0b.x 25o.x 75o.x _cons
>
> . local n = regexr("`n'","[0-9]+o\..+","")     // Also get rid of category values before the "o."
> . di "`n'"
>
> I'm sure there are other situations that I am missing here, so caveat emptor...
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Joe Canner
> Sent: Monday, March 10, 2014 10:09 AM
> To: [email protected]
> Subject: RE: st: Get list of non-omitted variables after a regression
>
> 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/
>
> *
> *   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index