Announcement

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

  • How to implement -xtdpdml- with interaction terms?

    Hi Statalist,

    In my paper I validate a theoretical proposition through the following FE regression:
    Code:
    areg y x1##x2 i.round,a(id)
    where y,x1,x2 are binary variables.

    There is some concern that there might be reverse causality from y to x1.

    Based on Leszczensky, L., & Wolbring, T. (2019) (available here) I am trying to implement the ML-SEM method through the -xtdpdml- command, as robustness check. I have gone through Moral-Benito,Allison,Williams,2016 guide on the command.

    Based on my understanding, both x1 and x2 would be predetermined variables in my example. However, I'm not sure how to express the interaction
    Code:
    x1##x2
    while using this command.
    According to the guide, the syntax should be
    Code:
    xtdpdml depvar strictly_exogenous_variable, inv(time_invariant_variable) pre(predetermined variable)
    Should the
    Code:
    x1##x2
    go inside the predetermined variable?

    Moreover, in my original specification, the time invariant variable was incorporated by absorbing individual level fixed effects through
    Code:
    ,a(id)
    . I'm not able to understand how I'm going to incorporate the fixed effects in this syntax, and whether I would need separate set of data for time invariant variables to include under
    Code:
    inv
    .

    I understand this question might seem confusing. It's partly because I myself am confused about how this command is working. i would appreciate it if you asked for further clarification if you need to help me out here.

    Thanks,


    Edited to add: I tried by adding interaction term in pre():
    Code:
    xtdpdml y, pre(L.x1##L.x2) tfix
    and got the following error
    Code:
    factor variables not allowed
    (error in option predetermined())
    When I changed i into
    Code:
    xtdpdml y, pre(L.x1) tfix
    , I got
    Code:
    no observations
    r(2000);
    Last edited by Titir Bhattacharya; 20 Feb 2022, 02:12.

  • #2
    Titir Bhattacharya your variables have repeated measures (panel data) right? Inputting some data would help

    Comment


    • #3
      Stata’s sem command (and hence xtdpdml) does not support factor variable notation. Hence, you need to compute the interaction terms yourself before running xtdpdml.

      Why don’t you get the interaction term working and then return if you have more Qs.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 18.5 MP (2 processor)

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

      Comment


      • #4
        Originally posted by Richard Williams View Post
        Stata’s sem command (and hence xtdpdml) does not support factor variable notation. Hence, you need to compute the interaction terms yourself before running xtdpdml.

        Why don’t you get the interaction term working and then return if you have more Qs.
        Thanks Richard. I'll do that

        Comment


        • #5
          Originally posted by Tom Scott View Post
          Titir Bhattacharya your variables have repeated measures (panel data) right? Inputting some data would help
          Sure Tom, I'll do that

          Comment


          • #6
            Originally posted by Tom Scott View Post
            Titir Bhattacharya your variables have repeated measures (panel data) right? Inputting some data would help
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input str8 id float(round y x1 x2)
            "IN010001" 2 . . .
            "IN010001" 3 1 1 1
            "IN010001" 4 1 1 0
            "IN010001" 5 1 1 0
            "IN010002" 2 . . .
            "IN010002" 3 1 1 1
            "IN010002" 4 1 1 1
            "IN010002" 5 0 1 0
            "IN010003" 2 . . .
            "IN010003" 3 1 1 1
            "IN010003" 4 1 0 0
            "IN010003" 5 1 0 1
            "IN010004" 2 . . .
            "IN010004" 3 1 1 0
            "IN010004" 4 1 1 0
            "IN010004" 5 1 1 0
            "IN010005" 2 . . .
            "IN010005" 3 0 0 1
            "IN010005" 4 1 1 0
            "IN010005" 5 1 1 0
            "IN010006" 2 . . .
            "IN010006" 3 0 1 1
            "IN010007" 2 . . .
            "IN010007" 3 0 1 1
            "IN010007" 4 0 1 0
            "IN010007" 5 0 1 0
            "IN010008" 2 . . .
            "IN010008" 3 1 1 0
            "IN010008" 4 0 0 0
            "IN010008" 5 0 0 1
            "IN010009" 2 . . .
            "IN010009" 3 1 1 1
            "IN010009" 4 1 1 0
            "IN010009" 5 1 0 1
            "IN010010" 2 . . .
            "IN010010" 3 1 1 1
            "IN010010" 4 1 1 0
            "IN010010" 5 1 1 0
            "IN010011" 2 . . .
            "IN010011" 3 1 1 1
            "IN010011" 4 0 1 0
            "IN010011" 5 1 0 0
            "IN010012" 2 . . .
            "IN010012" 3 1 1 1
            "IN010012" 4 1 1 0
            "IN010012" 5 1 0 0
            "IN010013" 2 . . .
            "IN010013" 3 1 0 0
            "IN010013" 4 1 1 1
            "IN010013" 5 1 1 0
            "IN010014" 2 . . .
            "IN010014" 3 1 1 0
            "IN010014" 4 1 1 0
            "IN010014" 5 1 1 1
            "IN010015" 2 . . .
            "IN010015" 3 0 1 1
            "IN010015" 4 1 1 0
            "IN010015" 5 1 1 1
            "IN010016" 2 . . .
            "IN010016" 3 0 1 0
            "IN010016" 4 1 1 0
            "IN010016" 5 1 1 0
            "IN010017" 2 . . .
            "IN010017" 3 1 1 0
            "IN010017" 4 1 1 0
            "IN010017" 5 1 0 0
            "IN010018" 2 . . .
            "IN010018" 3 1 1 0
            "IN010018" 4 1 1 0
            "IN010018" 5 1 1 0
            "IN010019" 2 . . .
            "IN010019" 3 1 1 1
            "IN010019" 4 1 0 0
            "IN010019" 5 1 1 1
            "IN010020" 2 . . .
            "IN010020" 3 1 0 1
            "IN010020" 4 1 0 0
            "IN010020" 5 0 0 0
            "IN010021" 2 . . .
            "IN010021" 3 1 1 0
            "IN010021" 4 1 1 0
            "IN010021" 5 1 1 0
            "IN010023" 2 . . .
            "IN010023" 3 1 1 0
            "IN010023" 4 1 1 0
            "IN010023" 5 1 1 0
            "IN010024" 2 . . .
            "IN010024" 3 1 1 1
            "IN010024" 4 1 1 0
            "IN010024" 5 1 1 1
            "IN010025" 2 . . .
            "IN010025" 3 0 1 0
            "IN010025" 4 0 0 0
            "IN010025" 5 0 0 1
            "IN010026" 2 . . .
            "IN010026" 3 1 1 0
            "IN010026" 4 1 1 1
            "IN010026" 5 1 1 1
            "IN010027" 2 . . .
            "IN010027" 3 0 1 1
            end

            Comment


            • #7
              A couple of comments:
              • I assume round is supposed to be the time var? Or did you not include the time var in your extract?
              • When round = 2, y, x1, and x2 have missing values. If that is true for the entire data set you might as well drop cases where round = 2.
              This is the code I ran.

              encode id, gen(idnum)
              xtset idnum round
              drop if round == 2 // All other vars are missing when round == 2
              gen x1x2 = x1*x2
              xtdpdml y, pre(L.x1 L.x2 L.x1x2) tfix // Won't converge
              xtdpdml y, pre(L.x1 L.x2) tfix // Converges

              I don't know if that is getting close to what you want or not. But, by dropping round = 2, at least you can get results and tweak the model from here. You may want to add ylag(0) or do other tweaks.

              Also, at least in the extract, y is a 0/1 dichotomy. For your purposes, perhaps that is ok. But, xtdpdml wants y to be continuous. You might want to look at this thread, especially Allison's post in #5.

              https://www.statalist.org/forums/for...int-estimation
              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              StataNow Version: 18.5 MP (2 processor)

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

              Comment


              • #8
                You could consider running - xtdpdml y, pre(L.x1) tfix - at various levels of x2 as opposed to including an interaction

                Comment


                • #9
                  Originally posted by Richard Williams View Post
                  A couple of comments:
                  • I assume round is supposed to be the time var? Or did you not include the time var in your extract?
                  • When round = 2, y, x1, and x2 have missing values. If that is true for the entire data set you might as well drop cases where round = 2.
                  This is the code I ran.

                  encode id, gen(idnum)
                  xtset idnum round
                  drop if round == 2 // All other vars are missing when round == 2
                  gen x1x2 = x1*x2
                  xtdpdml y, pre(L.x1 L.x2 L.x1x2) tfix // Won't converge
                  xtdpdml y, pre(L.x1 L.x2) tfix // Converges

                  I don't know if that is getting close to what you want or not. But, by dropping round = 2, at least you can get results and tweak the model from here. You may want to add ylag(0) or do other tweaks.

                  Also, at least in the extract, y is a 0/1 dichotomy. For your purposes, perhaps that is ok. But, xtdpdml wants y to be continuous. You might want to look at this thread, especially Allison's post in #5.

                  https://www.statalist.org/forums/for...int-estimation
                  Thanks a lot Richard for your detailed explanation. It really helped clear things up and get me started.

                  Also, thanks for pointing me towards the relevant thread.

                  Comment


                  • #10
                    Originally posted by Tom Scott View Post
                    You could consider running - xtdpdml y, pre(L.x1) tfix - at various levels of x2 as opposed to including an interaction
                    Thanks Tom for the suggestion.

                    Comment

                    Working...
                    X