Announcement

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

  • SEM vs. 2sls (ivreg): Replicating Stata example

    Dear Colleagues,

    Need some help here to replicate an example from "ivreg" described here: http://www.stata.com/support/faqs/st...rsive-systems/ . I was attracted to a Note in the page where it says:

    Note: This model could also be fit with sem, using maximum likelihood instead of a two-step method.
    Example of ivreg:

    Code:
     
     sysuse auto   
     ivregress 2sls price displacement (trunk=headroom), small 
    Instrumental variables (2SLS) regression
    
          Source |       SS       df       MS              Number of obs =      74
    -------------+------------------------------           F(  2,    71) =   11.29
           Model |   108641939     2  54320969.4           Prob > F      =  0.0001
        Residual |   526423457    71  7414414.89           R-squared     =  0.1711
    -------------+------------------------------           Adj R-squared =  0.1477
           Total |   635065396    73  8699525.97           Root MSE      =  2722.9
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           trunk |  -222.3396   175.7292    -1.27   0.210    -572.7338    128.0545
    displacement |   22.19871   6.071088     3.66   0.000      10.0933    34.30411
           _cons |   4844.184   1620.835     2.99   0.004     1612.331    8076.037
    ------------------------------------------------------------------------------
    Instrumented:  trunk
    Instruments:   displacement headroom
    As the Note above from the page suggests, the model can be fiitted with SEM and that is what I am interested in. What I would like to know is what would be the relevant SEM code to reproduce the same result. If I type the following:

    Code:
    sem (trunk <- headroom) ///
        (price <- displacement trunk),method(ml)
    
    It poduces the following and they are very different:
    
    ------------------------------------------------------------------------------
                   |                 OIM
                   |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    ---------------+----------------------------------------------------------------
    Structural     |
      trunk <-     |
          headroom |   3.347171   .4405193     7.60   0.000     2.483769    4.210573
             _cons |    3.73786    1.36955     2.73   0.006      1.05359    6.422129
      -------------+----------------------------------------------------------------
      price <-     |
             trunk |   14.33919   87.76796     0.16   0.870    -157.6828    186.3612
      displacement |    15.4894   4.087875     3.79   0.000      7.47731    23.50148
             _cons |    2911.98   1005.215     2.90   0.004     941.7949    4882.165
    ---------------+----------------------------------------------------------------
       var(e.trunk)|   10.13883   1.666814                      7.346008    13.99345
       var(e.price)|    6477314    1064864                       4693083     8939878
    --------------------------------------------------------------------------------

    Can anyone help in implementing the 2sls in SEM as the page prescribed? Many thanks.
    Roman

  • #2
    I think the code is something like

    Code:
    . sem (trunk <- headroom displacement) (price <- displacement trunk), method(ml) cov(e.trunk*e.price) nolog
    
    Endogenous variables
    
    Observed:  trunk price
    
    Exogenous variables
    
    Observed:  headroom displacement
    
    Structural equation model                       Number of obs      =        74
    Estimation method  = ml
    Log likelihood     = -1387.9682
    
    -------------------------------------------------------------------------------------
                        |                 OIM
                        |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    --------------------+----------------------------------------------------------------
    Structural          |
      trunk <-          |
               headroom |    2.43531   .4478109     5.44   0.000     1.557617    3.313003
           displacement |   .0177031   .0041252     4.29   0.000     .0096179    .0257883
                  _cons |   2.974509   1.238357     2.40   0.016     .5473744    5.401644
      ------------------+----------------------------------------------------------------
      price <-          |
                  trunk |  -222.3396   172.1303    -1.29   0.196    -559.7088    115.0296
           displacement |   22.19871   5.946753     3.73   0.000     10.54329    33.85413
                  _cons |   4844.184    1587.64     3.05   0.002     1732.467    7955.901
    --------------------+----------------------------------------------------------------
            var(e.trunk)|   8.118382   1.334654                      5.882106    11.20485
            var(e.price)|    7113831    1491621                       4716550    1.07e+07
    --------------------+----------------------------------------------------------------
    cov(e.trunk,e.price)|    2689.37   1682.547     1.60   0.110    -608.3611    5987.101
    -------------------------------------------------------------------------------------
    Note: The LR test of model vs. saturated is not reported because the fitted
          model is not full rank.
    
    .
    I had to include displacement in the trunk equation (which ivregress is also doing, right?) and then let the residuals for trunk and price be correlated. The only thing that worries me is the note at the end. But the numbers all seem fine (indeed, if you use liml with ivregress, the numbers match perfectly.)
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 16.1MP (2 processor)

    EMAIL: rwilliam@ND.Edu
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Thank you so much Richard for the correct codes. It's been a great help.
      Roman

      Comment


      • #4
        You are welcome. It just annoys me that it says the fitted model is not full rank. As far as I can tell, the model is just identified/saturated, and the LR stat should be zero. If you do estat resid, all the residuals are zero.

        FYI, a very good book on sem is http://www.stata.com/bookstore/disco...g-using-stata/
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        Stata Version: 16.1MP (2 processor)

        EMAIL: rwilliam@ND.Edu
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Thank you Richard, I actually just got the hold of the book and skimming through. But that help was something I needed now to understand the mechanism.

          Best.
          Roman

          Comment


          • #6
            I have one more question regarding SEM. I know I can use the SEM GUI chart builder for my model and estimate and copy the chart to my document. Is there any way to get the chart through commands in .do file as we get "marginsplot" after "margins" command?
            Roman

            Comment


            • #7
              If you are asking, can syntax generate the diagram, rather than the other way around -- as far as I know, the answer is no,
              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              Stata Version: 16.1MP (2 processor)

              EMAIL: rwilliam@ND.Edu
              WWW: https://www3.nd.edu/~rwilliam

              Comment


              • #8
                Thanks again Richard, at least I now know it and will not waste my time to search for it.
                Roman

                Comment


                • #9
                  Hi all:

                  Sorry for re-opening this old thread. I was wondering why "displacement" must also be included in the equation predicting "trunk" in Richard's post from 30 Jan 2015? This is really just a question about understanding what is going on "under the hood" of 2SLS. Thank you!

                  Comment


                  • #10
                    This is what 2SLS does, it models the endogenous right hand side variable as a function of all exogenous variables (both included exogenous, and excluded instruments).

                    It needs to be done this way to get consistent estimates in fully simultaneous systems.

                    It does not need to be done this way in triangular systems.

                    Originally posted by Henry Kohlsdorf View Post
                    Hi all:

                    Sorry for re-opening this old thread. I was wondering why "displacement" must also be included in the equation predicting "trunk" in Richard's post from 30 Jan 2015? This is really just a question about understanding what is going on "under the hood" of 2SLS. Thank you!

                    Comment


                    • #11
                      Also to straighten the record, because one might conclude false equivalences here. (Everything that Richard Williams said is correct, he even hinted at what I am saying next but did not really spell it out).

                      1. The correct equivalence is that -sem- applied on triangular systems gives you numerically the same results as -ivregress liml-, if you do like LIML does and include all exogenous variables in the equation for the endogenous right hand side variable (just like Richard did above).

                      2. Only in exactly identified triangular systems is -sem- equivalent to -ivregress 2sls- and equivalent to -ivregress liml-.

                      Comment

                      Working...
                      X