Announcement

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

  • Check if a coefficient exists

    Hi,

    I am running the following regression:
    Code:
    reg `var' i.Protection i.Consulting i.both gender educ base_tax_all
    looping over a list of variables. For some of the variables in the list, due to collinearity, coefficients of categorical variables i. Protection, i.Consulting and/or i.both do not exist (_b[1.Protection] for example if it is omitted).

    I was wondering if there is a way to check if a coefficient exists (similar to capture confirm for variables)?

    Thank you

  • #2
    As I'm not sure exactly how you want to use this, I'm not showing complete code. But look up -help _rmcoll-. -_rmcoll- is a command that accepts the varlist of the regression and then returns in r(varlist) a list of the variables as they will show up in the output. In particular, any variable that has b0. before it is omitted as the base category, and any variable that is preceded by o. is omitted due to some other colinearity.

    Code:
    sysuse auto, clear
    gen turn2 = turn*2 // COLINEAR WITH turn
    _rmcoll price i.foreign turn turn2
    display `"`r(varlist)'"'
    
    regress price i.foreign turn turn2
    While you can't use -confirm- to determine whether a variable has survived removal for colinearity, you can use the -strpos()- function to determine whether or not a particular variable's name is preceded by o. or b0 in the r(varlist) returned by _rmcoll and then branch your code accordingly with an -if- command (not -if- qualifier).

    Comment


    • #3
      That's exactly what I was looking for. Thank you Clyde

      Comment

      Working...
      X