Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Extracting Names from Stepwise Regression Output

    Hello All,
    I am writing because I have hit a bit of a problem that I cannot seem to figure out. I am using stepwise regression. I do understand the perils of stepwise regression, but I have my reasons for using it. Here is the issue that I am having. I need to be able to grab the names of the variables left in the stepwise regression. I can grab the coefficients from the matrix e(b) or the r(table), but I can't seem to grab the names of the variables. Once I grab the names, I want to be able to put those names into a local macro to use for other analyses. How do I do this so the 3 significant variable names are extracted and put into a local macro to be used in other analyses? Here is my sample code, note I did use dataex to generate the code listed below:


    clear
    sysuse auto
    generate weight2 = weight^2
    stepwise, pe(.05): regress mpg weight weight2 displ gear turn headroom foreign price
    ereturn list
    return list
    matrix var = e(b)
    matrix list var
    matrix table = r(table)
    matrix list table


    Any assistance with this will be helpful. What are some methods of grabbing the variable names of the 3 significant variables, and putting the names of the 3 variables into a local macro so that it could be used in other analyses? Thank you in advance


  • #2
    Several macro commands and functions are what you need.
    Code:
    . matrix list e(b)
    
    e(b)[1,4]
            weight     weight2     foreign       _cons
    y1  -.01657294   1.591e-06  -2.2035002   56.538839
    
    . local vars : colnames e(b)
    
    . macro list _vars
    _vars:          weight weight2 foreign _cons
    
    . local cons _cons
    
    . local vars : list vars - cons
    
    . macro list _vars
    _vars:          weight weight2 foreign

    Comment


    • #3
      This worked perfectly. I have been stuck on this for a while now. Thank you

      Comment

      Working...
      X