Announcement

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

  • elasticity calculation with a factor variable regression

    hi dear all statalisters,
    I now face a problem in getting the elasticity after running a logit model. To put it more understandable, I use this code as an example:
    Code:
    sysuse auto.dta,clear
    logit foreign turn length weight c.price#i.rep78
    margins, eyex(*)
    then there's an error information:
    factor variables not allowed in option eyex()
    how could I overcome this problem?
    Thanks in advance.
    2B or not 2B, that's a question!

  • #2
    Just as a side note: I fail to understand why adding an interaction term between price and rep78, and not adding the so-called "main effects".

    That being said, you may type:

    Code:
    margins, eyex( turn length weight  price )
    Best regards,

    Marcos

    Comment


    • #3
      In addition to Marcos helpful comments
      you cannot calculate elasticities with respect to a categorical variable, because the numerator is not correctly defined. You could calculate Semi-elasticities with respect to the categorical variable.
      Best

      Comment


      • #4
        Originally posted by Marcos Almeida View Post
        Just as a side note: I fail to understand why adding an interaction term between price and rep78, and not adding the so-called "main effects".

        That being said, you may type:

        Code:
        margins, eyex( turn length weight price )
        Dear Marcos, thank you for your explanation. Because in my paper, I want to change the cross-sectional data into a semi-panel data. i.e, I want to investigate the effect of price on the possibility of being a foreign car would change over time or not so I generate an interaction variable=price*in which year it was produced for example. Have I made a mistake?
        Last edited by Liu Qiang; 26 Feb 2019, 06:51.
        2B or not 2B, that's a question!

        Comment


        • #5
          Theoretically, I see no problem in using the interaction term, but I believe it should come with the predictors as well,

          Just adding an extra # will provide the predictors plus the interaction term.
          Best regards,

          Marcos

          Comment


          • #6
            Originally posted by Marcos Almeida View Post
            Theoretically, I see no problem in using the interaction term, but I believe it should come with the predictors as well,

            Just adding an extra # will provide the predictors plus the interaction term.
            thank you for your kind reminder. But how could I get the elasticity for each interaction term then?
            2B or not 2B, that's a question!

            Comment


            • #7
              You can easily have the answer for the question in #6, I mean, "why not".

              You just need to type:

              Code:
              . sysuse auto
              (1978 Automobile Data)
              
              . logit foreign turn length weight c.price##i.rep78
              
              note: 1.rep78 != 0 predicts failure perfectly
                    1.rep78 dropped and 2 obs not used
              
              note: 2.rep78 != 0 predicts failure perfectly
                    2.rep78 dropped and 8 obs not used
              
              note: 5.rep78 omitted because of collinearity
              note: 2.rep78#c.price omitted because of collinearity
              note: 5.rep78#c.price omitted because of collinearity
              Iteration 0:   log likelihood = -38.411464  
              Iteration 1:   log likelihood = -14.747241  
              Iteration 2:   log likelihood = -11.766559  
              Iteration 3:   log likelihood = -11.015015  
              Iteration 4:   log likelihood = -10.945121  
              Iteration 5:   log likelihood = -10.944407  
              Iteration 6:   log likelihood = -10.944406  
              
              Logistic regression                             Number of obs     =         59
                                                              LR chi2(8)        =      54.93
                                                              Prob > chi2       =     0.0000
              Log likelihood = -10.944406                     Pseudo R2         =     0.7151
              
              -------------------------------------------------------------------------------
                    foreign |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
              --------------+----------------------------------------------------------------
                       turn |  -.4981345   .4036253    -1.23   0.217    -1.289226    .2929566
                     length |   .0328362   .1129737     0.29   0.771    -.1885882    .2542606
                     weight |  -.0044512   .0035285    -1.26   0.207     -.011367    .0024645
                      price |   .0019742   .0012189     1.62   0.105    -.0004147    .0043631
                            |
                      rep78 |
                         1  |          0  (empty)
                         2  |          0  (empty)
                         3  |   4.447291   5.735345     0.78   0.438    -6.793777    15.68836
                         4  |  -.5519409   7.950418    -0.07   0.945    -16.13447    15.03059
                         5  |          0  (omitted)
                            |
              rep78#c.price |
                         1  |          0  (empty)
                         2  |          0  (empty)
                         3  |  -.0012724   .0012456    -1.02   0.307    -.0037137    .0011688
                         4  |  -.0001351   .0015902    -0.08   0.932    -.0032518    .0029816
                         5  |          0  (omitted)
                            |
                      _cons |   14.12164   19.74753     0.72   0.475    -24.58281     52.8261
              -------------------------------------------------------------------------------
              
              . margins, eyex( turn length weight  price )
              
              Average marginal effects                        Number of obs     =         59
              Model VCE    : OIM
              
              Expression   : Pr(foreign), predict()
              ey/ex w.r.t. : turn length weight price
              
              ------------------------------------------------------------------------------
                           |            Delta-method
                           |      ey/ex   Std. Err.      z    P>|z|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
                      turn |   -13.3061   10.81663    -1.23   0.219    -34.50631    7.894107
                    length |   4.175763   14.36291     0.29   0.771    -23.97502    32.32655
                    weight |  -9.705913   7.721956    -1.26   0.209    -24.84067    5.428842
                     price |   4.053252    2.70474     1.50   0.134     -1.24794    9.354445
              ------------------------------------------------------------------------------
              
              . margins, eyex( turn length weight  price rep78)
              factor variables not allowed in option eyex()
              r(198);
              
              . margins, eyex( turn length weight  price#rep78)
              invalid eyex() option;
              levels of interactions not allowed
              r(198);
              
              . margins, eyex( turn length#weight  price)
              invalid eyex() option;
              levels of interactions not allowed
              r(198);
              Hopefully that helps.
              Best regards,

              Marcos

              Comment


              • #8
                Originally posted by Marcos Almeida View Post
                You can easily have the answer for the question in #6, I mean, "why not".

                You just need to type:

                Code:
                . sysuse auto
                (1978 Automobile Data)
                
                . logit foreign turn length weight c.price##i.rep78
                
                note: 1.rep78 != 0 predicts failure perfectly
                1.rep78 dropped and 2 obs not used
                
                note: 2.rep78 != 0 predicts failure perfectly
                2.rep78 dropped and 8 obs not used
                
                note: 5.rep78 omitted because of collinearity
                note: 2.rep78#c.price omitted because of collinearity
                note: 5.rep78#c.price omitted because of collinearity
                Iteration 0: log likelihood = -38.411464
                Iteration 1: log likelihood = -14.747241
                Iteration 2: log likelihood = -11.766559
                Iteration 3: log likelihood = -11.015015
                Iteration 4: log likelihood = -10.945121
                Iteration 5: log likelihood = -10.944407
                Iteration 6: log likelihood = -10.944406
                
                Logistic regression Number of obs = 59
                LR chi2(8) = 54.93
                Prob > chi2 = 0.0000
                Log likelihood = -10.944406 Pseudo R2 = 0.7151
                
                -------------------------------------------------------------------------------
                foreign | Coef. Std. Err. z P>|z| [95% Conf. Interval]
                --------------+----------------------------------------------------------------
                turn | -.4981345 .4036253 -1.23 0.217 -1.289226 .2929566
                length | .0328362 .1129737 0.29 0.771 -.1885882 .2542606
                weight | -.0044512 .0035285 -1.26 0.207 -.011367 .0024645
                price | .0019742 .0012189 1.62 0.105 -.0004147 .0043631
                |
                rep78 |
                1 | 0 (empty)
                2 | 0 (empty)
                3 | 4.447291 5.735345 0.78 0.438 -6.793777 15.68836
                4 | -.5519409 7.950418 -0.07 0.945 -16.13447 15.03059
                5 | 0 (omitted)
                |
                rep78#c.price |
                1 | 0 (empty)
                2 | 0 (empty)
                3 | -.0012724 .0012456 -1.02 0.307 -.0037137 .0011688
                4 | -.0001351 .0015902 -0.08 0.932 -.0032518 .0029816
                5 | 0 (omitted)
                |
                _cons | 14.12164 19.74753 0.72 0.475 -24.58281 52.8261
                -------------------------------------------------------------------------------
                
                . margins, eyex( turn length weight price )
                
                Average marginal effects Number of obs = 59
                Model VCE : OIM
                
                Expression : Pr(foreign), predict()
                ey/ex w.r.t. : turn length weight price
                
                ------------------------------------------------------------------------------
                | Delta-method
                | ey/ex Std. Err. z P>|z| [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                turn | -13.3061 10.81663 -1.23 0.219 -34.50631 7.894107
                length | 4.175763 14.36291 0.29 0.771 -23.97502 32.32655
                weight | -9.705913 7.721956 -1.26 0.209 -24.84067 5.428842
                price | 4.053252 2.70474 1.50 0.134 -1.24794 9.354445
                ------------------------------------------------------------------------------
                
                . margins, eyex( turn length weight price rep78)
                factor variables not allowed in option eyex()
                r(198);
                
                . margins, eyex( turn length weight price#rep78)
                invalid eyex() option;
                levels of interactions not allowed
                r(198);
                
                . margins, eyex( turn length#weight price)
                invalid eyex() option;
                levels of interactions not allowed
                r(198);
                Hopefully that helps.
                thanks! I understand what's wrong now. I have made a mistake.
                2B or not 2B, that's a question!

                Comment

                Working...
                X