Announcement

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

  • #31
    Hi Jerry. I haven't tried constraints but I believe they can work. Specifying them is not as straightforward as what you wrote though.

    Consider this example:

    Code:
    . use https://www3.nd.edu/~rwilliam/statafiles/wages, clear
    
    . xtset id t
    
    Panel variable: id (strongly balanced)
     Time variable: t, 1 to 7
             Delta: 1 unit
    
    . quietly xtdpdml wks L.lwage, inv(ed) pre(L.union) ti(Baseline Model) semfile(xtest, r)
    
    . type xtest.do
    #delimit ;
    sem (wks2 <- wks1@b1 lwage1@b2 union1@b3 ed@b4 Alpha@1
        E2@1 ) (wks3 <- wks2@b1 lwage2@b2 union2@b3 ed@b4 Alpha@1
        E3@1 ) (wks4 <- wks3@b1 lwage3@b2 union3@b3 ed@b4 Alpha@1
        E4@1 ) (wks5 <- wks4@b1 lwage4@b2 union4@b3 ed@b4 Alpha@1
        E5@1 ) (wks6 <- wks5@b1 lwage5@b2 union5@b3 ed@b4 Alpha@1
        E6@1 ) (wks7 <- wks6@b1 lwage6@b2 union6@b3 ed@b4 Alpha@1
        ), var(e.wks2@0 e.wks3@0 e.wks4@0 e.wks5@0 e.wks6@0)
        var(Alpha) cov(Alpha*(ed)@0 Alpha*(E2 E3 E4 E5 E6)@0
        _OEx*(E2 E3 E4 E5 E6)@0 E2*(E3 E4 E5 E6)@0 E3*(E4 E5 E6)@0
        E4*(E5 E6)@0 E5*(E6)@0 union3*(E2) union4*(E2 E3)
        union5*(E2 E3 E4) union6*(E2 E3 E4 E5)) iterate(250)
        technique(nr 25 bhhh 25) noxconditional;
    #delimit cr
    The data set is in long format. wks, lwage, and union are time varying, while ed is time invariant.

    xtdpdml reshapes the data from long to wide, so sem can analyze it with sem. After reshaping, the time-varying variables have names like wks2, wks3, lwage1, lwage2, union4, union5, etc. The time-invariant ed is just called ed.

    So, the problem with a constraints command is that the variable names aren't right once the data are reshaped wide. Further complicating things is that the reshaped var names depend on your lag structure. Also, you might have lag 2 and lag 3 versions of a variable in a model -- which would you want constrained?

    So, I would probably do something like this:

    Code:
    xtdpdml wks L.lwage, inv(ed) pre(L.union) ti(Baseline Model) semfile(xtest, r) dryrun staywide
    and then I would hand-edit xtest.do with the constraints I want, e.g. set the effects of lagged union equal to 1:

    Code:
    #delimit ;
    sem (wks2 <- wks1@b1 lwage1@b2 union1@1 ed@b4 Alpha@1
        E2@1 ) (wks3 <- wks2@b1 lwage2@b2 union2@1 ed@b4 Alpha@1
        E3@1 ) (wks4 <- wks3@b1 lwage3@b2 union3@1 ed@b4 Alpha@1
        E4@1 ) (wks5 <- wks4@b1 lwage4@b2 union4@1 ed@b4 Alpha@1
        E5@1 ) (wks6 <- wks5@b1 lwage5@b2 union5@1 ed@b4 Alpha@1
        E6@1 ) (wks7 <- wks6@b1 lwage6@b2 union6@1 ed@b4 Alpha@1
        ), var(e.wks2@0 e.wks3@0 e.wks4@0 e.wks5@0 e.wks6@0)
        var(Alpha) cov(Alpha*(ed)@0 Alpha*(E2 E3 E4 E5 E6)@0
        _OEx*(E2 E3 E4 E5 E6)@0 E2*(E3 E4 E5 E6)@0 E3*(E4 E5 E6)@0
        E4*(E5 E6)@0 E5*(E6)@0 union3*(E2) union4*(E2 E3)
        union5*(E2 E3 E4) union6*(E2 E3 E4 E5)) iterate(250)
        technique(nr 25 bhhh 25) noxconditional;
    #delimit cr
    There are probably other and maybe easier ways to do this, but this seems like a relatively straightforward way to me. If there were huge demand for such a feature I might see if there are easier ways to program it.

    But in general, if xtdpdml can't quite do what you want, letting it generate the code to get you started and then tweaking it will sometimes solve your problem.
    Last edited by Richard Williams; 26 Sep 2021, 14:18.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 17.0 MP (2 processor)

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

    Comment


    • #32
      To my pleasant surprise, this code works:

      Code:
      use https://www3.nd.edu/~rwilliam/statafiles/wages, clear
      xtset id t
      xtdpdml wks L.lwage, inv(ed) pre(L.union) ti(Baseline Model)
      constraint 1 union1 = 1
      xtdpdml wks L.lwage, inv(ed) pre(L.union) ti(Baseline Model) semopts(constraint(1))
      The last highlights output is

      Code:
      . xtdpdml wks L.lwage, inv(ed) pre(L.union) ti(Baseline Model) semopts(constraint(1))
      
      Highlights: Baseline Model
      ------------------------------------------------------------------------------
                   |                 OIM
               wks | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
      -------------+----------------------------------------------------------------
      wks          |
               wks |
               L1. |    .182648   .0201157     9.08   0.000     .1432219     .222074
                   |
             lwage |
               L1. |   .5437444   .4846287     1.12   0.262    -.4061105    1.493599
                   |
             union |
               L1. |          1   5.36e-16  1.9e+15   0.000            1           1
                   |
                ed |  -.0046658   .0529046    -0.09   0.930    -.1083568    .0990252
      ------------------------------------------------------------------------------
      # of units = 595. # of periods = 7. First dependent variable is from period 2. 
      Constants are free to vary across time periods
      LR test of model vs. saturated: chi2(72)  =     128.15, Prob > chi2 =  0.0001
      IC Measures: BIC =   25481.95  AIC =   24788.56
      Wald test of all coeff = 0: chi2(3) =      84.63, Prob > chi2 =  0.0000
      In order to pull this off, I had to know what the right name for the constraint is. It also had to be true that the coefficients for union1, union2, union3, etc. were already constrained to be equal. And this might not work, or be prone to error, in a more complicated situation. Hand-tweaking might be safer or necessary in some situations.

      But overall, if you are careful, constraints like this are possible with xtdpdml.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

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

      Comment


      • #33
        Thanks for the detailed answer!

        Comment


        • #34
          Dear Prof. Richard,
          Would it be possible for me to use xtdpdml if my n=2 and t=12?if not, given the nature of my data, can I even pursue dynamic panel data analysis?

          Comment


          • #35
            Dear Prof. Richard,
            I am working with a panel data set (four waves) that looks like this:

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input float(sum_helpfromchildren srh) byte(alter anzkind) float spouse byte female float iscedx
            0 5 59 0 1 1 3
            0 4 62 0 1 1 3
            0 4 65 0 1 1 3
            0 4 73 1 0 0 3
            0 3 76 1 0 0 3
            0 3 79 1 0 0 3
            0 4 59 2 0 1 2
            0 4 65 2 0 1 2
            0 4 68 2 0 1 2
            0 3 68 3 0 1 2
            0 4 71 3 0 1 2
            1 4 74 3 0 1 2
            0 4 77 3 0 1 2
            0 4 83 2 1 0 2
            0 3 86 2 1 0 2
            0 2 89 2 1 0 2
            0 4 74 1 1 0 2
            0 3 77 1 1 0 2
            0 3 74 0 1 0 3
            0 3 77 0 1 0 3
            0 3 80 0 1 0 3
            0 2 89 1 1 0 3
            0 1 92 4 1 0 3
            1 4 95 1 1 0 2
            0 3 97 1 1 0 2
            1 1 75 3 1 0 2
            0 1 78 3 1 0 2
            0 2 88 4 0 0 1
            0 2 91 4 0 0 1
            1 2 84 2 0 1 3
            1 3 87 1 0 1 3
            1 3 90 2 0 1 3
            1 3 93 2 0 1 3
            0 3 86 1 0 0 2
            1 3 89 1 0 0 2
            1 2 92 1 0 0 2
            0 4 90 2 0 0 3
            0 4 93 2 0 0 3
            1 2 85 2 1 0 1
            0 3 88 2 1 0 1
            1 1 91 2 1 0 1
            0 4 82 3 1 0 3
            0 3 85 3 1 0 3
            0 3 88 3 1 0 3
            0 5 91 0 0 1 2
            0 4 95 0 0 1 2
            0 4 97 0 0 1 2
            0 3 84 2 0 1 2
            0 3 87 2 0 1 2
            0 3 90 2 0 1 2
            0 3 93 1 0 1 2
            0 4 83 2 1 0 3
            0 3 86 1 1 0 3
            0 3 70 3 1 0 2
            0 4 73 3 1 0 2
            1 4 76 3 1 0 2
            0 4 84 0 0 1 2
            0 3 87 0 0 1 2
            0 3 90 0 0 1 2
            0 4 71 1 0 1 2
            0 2 77 1 0 1 2
            0 1 92 2 0 1 1
            0 1 95 2 0 1 1
            0 3 87 2 0 1 2
            1 4 90 2 0 1 2
            1 4 93 2 0 1 2
            0 2 79 2 1 1 1
            0 2 82 2 0 1 1
            0 4 74 2 1 1 3
            0 4 77 2 1 1 3
            0 4 80 2 1 1 3
            0 4 76 3 1 1 1
            0 3 79 3 1 1 1
            1 3 82 3 1 1 1
            1 3 93 4 0 0 2
            1 3 95 4 0 0 2
            1 4 67 1 1 1 2
            0 4 70 1 1 1 2
            0 3 73 1 1 1 2
            0 4 76 1 1 1 2
            0 4 70 1 1 1 2
            1 3 73 1 1 1 2
            0 3 76 1 1 1 2
            0 3 77 2 0 1 3
            1 4 80 2 0 1 3
            .a 3 83 2 0 1 3
            1 2 86 2 0 1 3
            0 3 78 3 0 0 2
            0 3 81 3 0 0 2
            0 2 84 3 0 0 2
            0 3 88 3 1 0 2
            0 1 91 3 1 0 2
            0 4 79 5 1 0 2
            1 4 82 5 1 0 2
            0 4 70 5 1 1 2
            0 4 76 5 1 1 2
            0 4 79 5 1 1 2
            0 3 88 0 0 1 1
            0 4 91 0 0 1 1
            0 4 86 2 0 1 3
            end
            label values alter ALTER_17
            label def ALTER_17 97 "97. 96-97", modify
            label values anzkind ANZKIND
            label def ANZKIND 0 "0. keine", modify

            I am trying to estimate a dynamic panel model with sum_helpfromchildren (binary 0/1) on srh (ordinal 1-5) and vice versa. The commands I use are as following:

            Code:
            xtdpdml sum_helpfromchildren alter anzkind spouse, pre(L.srh) inv(female iscedx) errorinv fiml decimals(3) gof
            xtdpdml srh alter anzkind spouse, pre(L.sum_helpfromchildren) inv(female iscedx) errorinv fiml decimals(3) gof
            However, as I understood it correctly my estimation does not work because sum_helpfromchildren and srh are not continuous?
            Thanks in advance for your help!
            Lisa

            Comment


            • #36
              Dear prof Richard,

              thanks for creating xtdpdml. However, I am not sure that my data is good for it. So, if you can advise me in that regard pls, I would be grateful.
              N= 13 and T = 19. so, is this why I always receive the error message below. I basically use this command to use the film option to handl missing data without imputation. I assume from literature there is reversal causality and persistency in my depvar, which is gini in my case, however I procced with the model step by step without adding any dynamic feature or predetermined vars. My model with the listwise deletion procedure yielded that random effect is better, so I added re in the options. ALso, I added tfix for coding years, fiml as I said for missing, ylags(0) to show results without addressing endogenity and have not specified predetermined . I added std as you have recommended but it gave me the same error message. I investigated normality, found that only lngini is normal but the rest of the explanatory variables (beginning from lngdp to govexp) are not normally distributed. tried to add vce(robust) as I read it deals with non-normality but all trials in vain. I am very new in stata, only learned 2 weeks ago

              thanks in advance

              --------------------------------------------------------------------------------
              name: <unnamed>
              log: E:\master\thesis\suggested topics\inequality\emperical\Untitled.smc
              > l
              log type: smcl
              opened on: 11 Nov 2022, 11:47:42

              . do "C:\Users\dell\AppData\Local\Temp\STD00000000. tmp"

              . xtdpdml lngini lngdp manu urb edu trade fdi internet avg_instit lnpop oilr gov
              > exp, std tfix re fiml ylags(0)
              st_matrixcolstripe(): 3200 conformability error
              _sem_build__cns_option(): - function returned error
              _sem_build__params(): - function returned error
              _sem_build(): - function returned error
              _sem_parse(): - function returned error
              st_sem_parse_and_build(): - function returned error
              <istmt>: - function returned error
              r(3200);

              end of do-file

              r(3200);
              Last edited by Nariman Sayed; 11 Nov 2022, 03:08.

              Comment


              • #37
                Dear Prof. Richard,
                Firstly i would like to thank you for this great command. It is very easy to use and life safer when analyzing low observation panel data.
                I have been wondering that what kind of problems solved when vce(robust) option used? For example, does it solve the cross-sectional, auto-correlation or heteroscedasticity problem?
                Best and kind regards.
                Emin

                Comment

                Working...
                X