Announcement

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

  • gsem vs xtdpdml

    In this article, Richard Williams explains why xtdpdml is better than SEM in analyzing panel data. But, what about gsem? In gsem unlike sem we can do multilevel analysis. Is it possible to define unit id as a second level variable and time as nested within the unitid? For example, for the following sample, does it make sense to combine these two equations with lagged dependent variables:

    Code:
    gsem (y <- l1.y mediator c.moderator##c.x1  M1[unit_id]) (mediator <- l1.medi c.moderator##c.x1  M1[unit_id]), vce(robust)

    If it's wrong, what is the correct way to run the above system of equations?

    Data:

    Code:
      
     clear
    input float(unit_id yearmonth y x1 x2 moderator mediator)
    3 648   -1.673604  -.7442273 -1.0363818  3.271517  3.790306
    3 649    .4038841  -.8535328 -1.0363818  3.174138  3.809004
    3 650     .562588 -1.1877229 -1.0363818  3.425862   3.77931
    3 651    1.291389  -1.146664 -1.0363818  3.412346 3.6407406
    3 652    .8052794 -1.1743647 -1.0363818 3.7186666  3.967077
    3 653  -.03675416  -.7409243 -1.0363818  3.219872  3.798276
    3 654   1.0632977  -.8755629 -1.0363818  3.466667 3.8156135
    3 655   -.5068667  -.8839995 -1.0363818  2.842949 3.8489246
    3 656    .5646673  -1.376372 -1.0363818  3.360119   3.63149
    3 657     .934234  -.8519906 -1.0363818 3.3083334 3.7305555
    3 658   .32183555 -.59005296   .7075664 3.7373564  3.793548
    4 648   -2.053771  -.8607342 -1.0363818  3.267277 3.7204175
    4 649  -.28470853  -.8418642 -1.0363818  3.773889  3.989841
    4 650    .1102932   -.457932 -1.0363818 3.4863095 3.9390345
    4 651    .5085503  -.2997211 -1.0363818 3.5165405      3.55
    4 652    .4732249 -.05104671 -1.0363818 3.5431216  3.605337
    4 653   -.3396801  -.3438883 -1.0363818 3.7653334 3.3848386
    4 654   -.8023075 -.59110814 -1.0363818  3.746795  3.404524
    4 655     .524676  -.6341597 -1.0363818 3.7515874 3.2825396
    4 656   -.0806455   -.442387 -1.0363818  3.571839 3.4154506
    4 657    .7601319  -.9101606 -1.0363818  4.146528 3.3850396
    4 658  -.29708236  -.7848284   .7053064   4.07963 3.9800696
    5 648  -.09884956 -2.3671591 -1.0363818 4.0142856 3.9034524
    5 649    .3637376 -2.0098896 -1.0363818  3.627564 3.9173334
    5 650    .5272369 -2.1749105 -1.0363818  3.279167  3.396795
    5 651    .4010301 -2.4400935 -1.0363818  3.641667  3.996528
    5 652   .03462299 -1.6249136 -1.0363818  3.607143  3.503472
    5 653   -.8958375  -1.634501 -1.0363818  3.972222 3.9333334
    5 654   -.8420179  -1.736356 -1.0363818 3.8314815 3.6791666
    5 655   -1.972452 -2.0890148 -1.0363818  3.801587 3.4958334
    5 656   -.8649931 -1.9769305 -1.0363818  3.795833 3.6608696
    5 657  -.13952091 -1.4404632 -1.0363818  3.608696 3.4591954
    5 658 -.035976883 -.23603535   .8973646     3.625  3.270988
    6 648    .6677211  .25581893 -1.0363818 3.5735295 3.5553334
    6 649     .997246   .4341331 -1.0363818 4.1704545  3.642529
    6 650    .6545075  .20891613 -1.0363818  3.142593  4.140199
    6 651    .8990768  .20612007 -1.0363818 3.4585884  4.068254
    6 652    .4727888   .3011284 -1.0363818 3.5944445  4.099575
    6 653   -.5000833   .2332805 -1.0363818  3.852193 3.8843474
    6 654   1.8032534  .33466095 -1.0363818  3.210563 3.9385715
    6 655   -.9693494  .03520535 -1.0363818 3.6065714  3.866164
    6 656   .05690836 -.14496662 -1.0363818 3.5489795  3.842613
    6 657     .463342   .1866461 -1.0363818 3.4930556  3.975397
    6 658   .16892995   .3850788   .6388407  3.357471  3.988834
    7 648    .7216926   .3505641 -1.0363818  3.864368  4.069512
    7 649    .8041119  .12411392 -1.0363818 3.4160714  3.954662
    7 650    .7418164  -.1596837 -1.0363818 4.1182795  4.158704
    7 651    .8701565 -.15722057 -1.0363818  4.010552 4.4940276
    7 652    .7349644 .025661064 -1.0363818  4.110931   4.38009
    7 653   .12824593  .10673832 -1.0363818 4.4591713 4.4671345
    7 654   .58063346  .29550174 -1.0363818  4.526656  4.651618
    7 655   .10464822   .3558027 -1.0363818  4.379938  4.608889
    7 656    .4740608   .3864914 -1.0363818   4.61358 4.4431086
    7 657    .4891589   .3713816 -1.0363818  4.579167 4.3469625
    7 658   .21748453   1.371178   1.101524  4.451282  4.410873
    end
    format %tm yearmonth
    Last edited by Monica Muller; 19 Feb 2018, 17:41.

  • #2
    First off, the xtdpdml support page is at

    https://www3.nd.edu/~rwilliam/dynamic/index.html

    It includes various papers, including a just accepted article for Stata Journal.

    It is true that xtdpdml can only do so much. For example, it couldn't, say, handle dependent variables where logistic regression was appropriate.

    But, hand-coding xtdpdml's models can be a nightmare, which is a big reason we wrote the program. xtdpdml makes it easy to use sem to estimate its models. Further, we argue that in many cases, our approach is superior to Arellano/Bond and related techniques that are widely used.

    You could, in theory, have xtdpdml generate as much of the Stata code as it could, and then hand tweak for gsem or other model variations.

    Anyway, it is sort of an apples and oranges comparison. xtdpdml can't do everything, but what it does do it does it pretty well. If you want something different, you'll have to do something else (but you may want to consider having xtdpdml start the coding process for you.)
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://academicweb.nd.edu/~rwilliam/

    Comment


    • #3
      Thanks Richard for your answer. I totally understand xtdpdml is superior to SEM for panel data. But, since I need to run the system of equations I was wondering whether gsem can deal with the panel data issue that you addressed about SEM or I need to find another solution?
      I really appreciate your help.

      Comment


      • #4
        Is this missing from your exanple?

        xtset unit_id yearmonth


        What is the purpose of M1[unit_id]? I'm not clear on what that code does. Maybe it is gsem specific.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://academicweb.nd.edu/~rwilliam/

        Comment


        • #5
          Yes, sorry! I missed including the xtset line.

          M1[unit_id] is unique to gsem. I followed this powerpoint by Chuck Huber for that. Unlike sem, in gsem we can do multilevel analysis. M1[unit_id] identifies unit_id as a higher level variable. I am not sure if I am correctly using it. But my purpose is to tell gsem that over time data are nested within unit_id. I thought using this we might not need to convert the data to the wide format and be able to avoid the complication of sem coding for panel data.

          Comment


          • #6
            I asked Paul Allison what he thought. He agreed with my comments, and added "But one other point is that when gsem is used in the multilevel mode, you can't include lagged values of the dependent variable. [The code shown will run] but it violates the assumption that predictors can't be correlated with the error term."
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            StataNow Version: 19.5 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://academicweb.nd.edu/~rwilliam/

            Comment


            • #7
              Thank you very much. It's very valuable information. Do you have any suggestions as to how I should run my system of equations when I have panel data and autoregression in this case? Do you think first differencing the DV instead of including the lagged DV might help?

              (1) y <- l1.y mediator c.moderator##c.x1

              (2) mediator <- l1.mediator c.moderator##c.x1
              Last edited by Monica Muller; 20 Feb 2018, 11:28.

              Comment

              Working...
              X