Announcement

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

  • -contrast- function not finding variables that exist

    I am trying to contrast the variables "race" and "vaccine". Both variables contained negative value labels in the dataset. I changed this with
    Code:
    egen race = group(w5_best_race), label
    egen vaccine = group(w5_nc_cvhadvac), label

    I can run regressions with the new variables, however when I try contrast
    Code:
    contrast race@vaccine, effects
    contrast vaccine@race, effects

    I get the following output:
    variable race not found
    r(111);

    and

    variable vaccine not found
    r(111);

    respectively

    Despite being able to use the variables in regression and view them with -tab- and see them in my variables list. They definitely exist.

  • #2
    Can't see your regression code. Could it be the problem of factor variable notation? Example:

    Code:
    sysuse auto, clear
    
    
    reg mpg rep78 foreign
    
          Source |       SS           df       MS      Number of obs   =        69
    -------------+----------------------------------   F(2, 66)        =     10.05
           Model |   546.30058         2   273.15029   Prob > F        =    0.0002
        Residual |  1793.90232        66  27.1803382   R-squared       =    0.2334
    -------------+----------------------------------   Adj R-squared   =    0.2102
           Total |   2340.2029        68  34.4147485   Root MSE        =    5.2135
    
    ------------------------------------------------------------------------------
             mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
           rep78 |   1.219096   .7926102     1.54   0.129    -.3634013    2.801593
         foreign |   4.202036   1.692832     2.48   0.016     .8221878    7.581885
           _cons |   15.85898   2.509808     6.32   0.000     10.84799    20.86997
    ------------------------------------------------------------------------------
    
    
    contrast rep78@foreign
    factor rep78 not found in list of covariates
    
    //Using fv notation:
    
    reg mpg i.rep78 i.foreign
    
          Source |       SS           df       MS      Number of obs   =        69
    -------------+----------------------------------   F(5, 63)        =      4.96
           Model |  661.189524         5  132.237905   Prob > F        =    0.0007
        Residual |  1679.01337        63  26.6510059   R-squared       =    0.2825
    -------------+----------------------------------   Adj R-squared   =    0.2256
           Total |   2340.2029        68  34.4147485   Root MSE        =    5.1625
    
    ------------------------------------------------------------------------------
             mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
           rep78 |
              2  |     -1.875   4.081284    -0.46   0.648     -10.0308    6.280795
              3  |  -1.922325   3.774126    -0.51   0.612    -9.464315    5.619665
              4  |  -1.111626   3.944633    -0.28   0.779    -8.994346    6.771095
              5  |   3.453704   4.215132     0.82   0.416    -4.969565    11.87697
                 |
         foreign |
        Foreign  |   3.556584   1.736681     2.05   0.045     .0861046    7.027064
           _cons |         21   3.650411     5.75   0.000     13.70524    28.29476
    ------------------------------------------------------------------------------
    
    contrast rep78@foreign, effects
    
    Contrasts of marginal linear predictions
    
    Margins: asbalanced
    
    -------------------------------------------------
                  |         df           F        P>F
    --------------+----------------------------------
    rep78@foreign |
        Domestic  |          4        1.68     0.1655
         Foreign  |          4        1.68     0.1655
           Joint  |          4        1.68     0.1655
                  |
      Denominator |         63
    -------------------------------------------------
    
    ---------------------------------------------------------------------------------------
                          |   Contrast   Std. err.      t    P>|t|     [95% conf. interval]
    ----------------------+----------------------------------------------------------------
            rep78@foreign |
    (2 vs base) Domestic  |     -1.875   4.081284    -0.46   0.648     -10.0308    6.280795
     (2 vs base) Foreign  |     -1.875   4.081284    -0.46   0.648     -10.0308    6.280795
    (3 vs base) Domestic  |  -1.922325   3.774126    -0.51   0.612    -9.464315    5.619665
     (3 vs base) Foreign  |  -1.922325   3.774126    -0.51   0.612    -9.464315    5.619665
    (4 vs base) Domestic  |  -1.111626   3.944633    -0.28   0.779    -8.994346    6.771095
     (4 vs base) Foreign  |  -1.111626   3.944633    -0.28   0.779    -8.994346    6.771095
    (5 vs base) Domestic  |   3.453704   4.215132     0.82   0.416    -4.969565    11.87697
     (5 vs base) Foreign  |   3.453704   4.215132     0.82   0.416    -4.969565    11.87697
    ---------------------------------------------------------------------------------------
    Roman

    Comment


    • #3
      As Roman Mostazir points out, the contrast command (not function) expects a termlist and bare variable names will not work unless they have been used previously in an estimation command using factor variable notation.

      Comment


      • #4
        Thank you Roman Mostazir and Nick Cox, I was doing multinomial logistic regression with the two variables before. After running a linear regression with the factor variable notation the contrast command worked fine.

        Comment

        Working...
        X