Announcement

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

  • Margins after SUEST when one equation is a ologit

    I estimate a system of equations (continous dependent variables) with SUEST and then calculate margins as follows:

    sysuse auto, clear
    reg weight rep turn trunk
    est store we_model
    regress price turn trunk
    est store ols_model

    // Combine the models using suest
    suest we_model ols_model
    margins, dydx(turn trunk) predict(equation(we_model_mean )) atmeans post

    suest we_model ols_model
    margins, dydx(turn trunk) predict(equation(ols_model_mean )) atmeans post



    Everything works, BUT, once I substitute one of the DEPENDENT VARIABLES for a ordered categorical variable, THE PROCEDURE DOES NOT WORK WITH MARGINS OF THE ORDERED CATEGORICAL VARIABLE.

    sysuse auto, clear

    ologit rep turn trunk
    est store olg_model

    regress price turn trunk
    est store ols_model

    suest olg_model ols_model
    margins, dydx(turn trunk) predict(equation(ols_model_mean)) atmeans post

    THE MARGINAL EFFECT HERE IS CALCULATED WITH EXPRESSION, SO I DO NOT FIND A CORRECT WAY TO MENTION THE NAME OF THE EQUATION ASSIGNED BY SUEST "olg_model_rep78 "

    suest olg_model ols_model
    margins, dydx(turn trunk) expression(logit(xb() - _b[/cut1]) - logit(xb() - _b[/cut2]))


    HOWEVER THIS WORK IF YOU ONLY HAVE ONE EQUATION WIHT PROBIT

    oprobit rep turn trunk
    est store o1
    margins, dydx(turn) expression(normal(xb() - _b[/cut1]) - normal(xb() - _b[/cut2]) )


    COULD ANYONE HELP ME TO IDENTIFY THE MARGINAL EFFECTS AFTER SUEST IN THE SECOND EQUATION BEING A OLOGIT ??

    THANKS

    Last edited by Ana Moro; 26 Mar 2025, 07:25.

  • #2
    Originally posted by Ana Moro View Post
    I DO NOT FIND A CORRECT WAY TO MENTION THE NAME OF THE EQUATION ASSIGNED BY SUEST "olg_model_rep78 "

    With suest, you have the -coeflegend- option that enables you to see how to reference the coefficients.

    Code:
    suest olg_model ols_model, coeflegend
    Last edited by Andrew Musau; 26 Mar 2025, 09:22.

    Comment


    • #3
      Thanks Andrew, I knew this option, but thanks for remind me.

      But my problem is more: "how to use the name of the equations in margins".

      The equation is named "ols_model_mean" or "olg_model_rep78".

      In the OLS, when calculating the margins there is no problem to call the equation as :

      margins, dydx(turn trunk) predict(equation(ols_model_mean)) atmeans post

      THE PROBLEM appears here when we do not use predict but expression

      margins, dydx(turn trunk) expression(logit(xb() - _b[/cut1]) - logit(xb() - _b[/cut2]))
      Last edited by Ana Moro; 26 Mar 2025, 10:46.

      Comment


      • #4
        I think you need -invlogit()- to replicate the margins calculation.

        Code:
        help invlogit()

        Code:
        sysuse auto, clear
        ologit rep turn trunk
        margins, dydx(turn trunk) predict(outcome(2))
        
        *USING -expression()-
        margins, dydx(turn trunk) expression(invlogit(xb() - _b[/cut1]) - invlogit(xb() - _b[/cut2]))
        Res.:

        Code:
        . ologit rep turn trunk
        
        Iteration 0:  Log likelihood = -93.692061  
        Iteration 1:  Log likelihood = -83.401763  
        Iteration 2:  Log likelihood =  -83.06925  
        Iteration 3:  Log likelihood = -83.068657  
        Iteration 4:  Log likelihood = -83.068657  
        
        Ordered logistic regression                             Number of obs =     69
                                                                LR chi2(2)    =  21.25
                                                                Prob > chi2   = 0.0000
        Log likelihood = -83.068657                             Pseudo R2     = 0.1134
        
        ------------------------------------------------------------------------------
               rep78 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                turn |   -.311434   .0794105    -3.92   0.000    -.4670757   -.1557923
               trunk |   .1104753   .0710693     1.55   0.120    -.0288179    .2497685
        -------------+----------------------------------------------------------------
               /cut1 |  -14.89839   2.874333                     -20.53198   -9.264803
               /cut2 |  -13.04965   2.773978                     -18.48655   -7.612753
               /cut3 |  -10.45379   2.587977                     -15.52613    -5.38145
               /cut4 |  -8.818894    2.50337                     -13.72541   -3.912379
        ------------------------------------------------------------------------------
        
        . 
        . margins, dydx(turn trunk) predict(outcome(2))
        
        Average marginal effects                                    Number of obs = 69
        Model VCE: OIM
        
        Expression: Pr(rep78==2), predict(outcome(2))
        dy/dx wrt:  turn trunk
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                turn |   .0246439   .0082119     3.00   0.003      .008549    .0407389
               trunk |   -.008742   .0059773    -1.46   0.144    -.0204573    .0029733
        ------------------------------------------------------------------------------
        
        . 
        . 
        . 
        . *USING -expression()-
        
        . 
        . margins, dydx(turn trunk) expression(invlogit(xb() - _b[/cut1]) - invlogit(xb() - _b[/cut2]))
        
        Average marginal effects                                    Number of obs = 69
        Model VCE: OIM
        
        Expression: invlogit(xb() - _b[/cut1]) - invlogit(xb() - _b[/cut2])
        dy/dx wrt:  turn trunk
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                turn |   .0246439   .0082119     3.00   0.003      .008549    .0407389
               trunk |   -.008742   .0059773    -1.46   0.144    -.0204573    .0029733
        ------------------------------------------------------------------------------
        
        .

        Comment


        • #5
          Thanks for the correction. For one equation is equivalent, as you have shown.

          My problem still is there, since I want to calculate margins after SUEST in the ologit equation.

          If you use "expression" you cannot use "predict" and then I do not know how to include the name of the equation.



          Comment


          • #6
            Should correspond to the column equation names of the e(b) matrix.

            Code:
            sysuse auto, clear
            regress price turn trunk
            est store ols_model
            ologit rep turn trunk
            est store olg_model
            suest olg_model ols_model
            display "`:coleq e(b)'"
            margins, dydx(turn trunk) predict(equation(olg_model_rep78))
            Res.:

            Code:
            . suest olg_model ols_model
            
            Simultaneous results for olg_model, ols_model               Number of obs = 74
            
            ---------------------------------------------------------------------------------
                            |               Robust
                            | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
            ----------------+----------------------------------------------------------------
            olg_model_rep78 |
                       turn |   -.311434   .0979628    -3.18   0.001    -.5034376   -.1194303
                      trunk |   .1104753   .0874306     1.26   0.206    -.0608856    .2818362
            ----------------+----------------------------------------------------------------
            /olg_model      |
                       cut1 |  -14.89839   3.252312                     -21.27281   -8.523977
                       cut2 |  -13.04965      3.131                      -19.1863   -6.913003
                       cut3 |  -10.45379   3.007877                     -16.34912   -4.558461
                       cut4 |  -8.818894   2.959499                     -14.61941   -3.018383
            ----------------+----------------------------------------------------------------
            ols_model_mean  |
                       turn |   126.6771   95.43345     1.33   0.184    -60.36903    313.7232
                      trunk |    138.437   72.38166     1.91   0.056     -3.42847    280.3024
                      _cons |  -761.7631   3069.361    -0.25   0.804    -6777.601    5254.075
            ----------------+----------------------------------------------------------------
            ols_model_lnvar |
                      _cons |    15.8769    .215662    73.62   0.000     15.45421    16.29959
            ---------------------------------------------------------------------------------
            
            . 
            . display "`:coleq e(b)'"
            olg_model_rep78 olg_model_rep78 /olg_model /olg_model /olg_model /olg_model ols_model_mean ols_model_mean ols_model_mean ols_model_lnvar
            
            . 
            . margins, dydx(turn trunk) predict(equation(olg_model_rep78))
            
            Average marginal effects                                    Number of obs = 74
            Model VCE: Robust
            
            Expression: Linear prediction, predict(equation(olg_model_rep78))
            dy/dx wrt:  turn trunk
            
            ------------------------------------------------------------------------------
                         |            Delta-method
                         |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                    turn |   -.311434   .0979628    -3.18   0.001    -.5034376   -.1194303
                   trunk |   .1104753   .0874306     1.26   0.206    -.0608856    .2818362
            ------------------------------------------------------------------------------
            
            .

            Comment


            • #7
              It is not mentioned why you want to use suest, but I'll set that aside and try to answer the question asked.

              You can specifiy the equation name within the xb() pseudo-function. So your call to margins would be
              Code:
              margins, dydx(turn trunk) ///
                      expression( ///
                                invlogit(xb(olg_model_rep78) - _b[/olg_model:cut1]) ///
                              - invlogit(xb(olg_model_rep78) - _b[/olg_model:cut2]) ///
                      )
              If you are trying to build a single table of marginal effects for both outcomes together, consider that gsem fits seemingly unrelated cross-sectional outcome models and has simpler predict syntax. Here is your example, but using gsem to fit the models.
              Code:
              gsem    (rep78 <- turn trunk, ologit) ///
                      (price <- turn trunk) ///
                      , vce(robust)
              
              margins, dydx(turn trunk)  ///
                      predict(mu outcome(rep78 2)) ///
                      predict(mu outcome(price))

              Comment


              • #8
                Thanks a lot Jeff! It is working!

                Comment

                Working...
                X