Announcement

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

  • Interaction Term

    Dear Statalister,

    In my empirical research, i am using the estimator from Driscoll and Kraay (1998) modified for Stata by Hoechle (2007) with the command XTSCC. In my research, i want to explore the interaction between few of my variables. However, the user-written command does not allow me to do that (c.GDPgrowth#c.DebtGDP). Due to this problem i manually multiply two of my interested variable (GDPgrowth * DebtGDP) but then when i want to calculate margins and have a margnisplot, the Stata does not recognize this as interactive variable.

    To be more clear, is there any way to have interaction in the regression under xtscc command?

    Thank you in advance,

  • #2
    Tareb:
    welcome to the list.
    You can probably create interactions via the (old) -xi- pefix, but cannot use -margins- and -marginsplot-.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      I believe the following is the current "home page" for the author of the xtscc command; if you have not done so already you might contact him to see if he can offer any advice.

      https://www.zhaw.ch/en/about-us/person/hoec/

      Comment


      • #4
        Dear Carlo and William,

        I highly appreciate your time, respectively for the replay.

        Kind regards,

        Comment


        • #5
          Hi all,
          I have similar question; I would like to use an interaction term that looks like
          Code:
           xtscc   depvar   i.person   independentvar   i.person#c.independentvar
          but Stata can't seem to read this command. I want to generate an interaction that will allow me to have a different coefficient for each person in my (unbalanced) panel so that I can see how the effect of the independent variable is hitting each person, but I am not sure how to generate this without using the factor notation within the regression. If I generate it manually
          Code:
          gen my_int = person*independentvar
          when I include it in my regression
          Code:
           xtscc depvar my_int i.person independentvar
          then I'm not sure how to allow it to vary for each dummy in the regression. If anyone has any thoughts on this matter, I would appreciate it!

          Thanks!

          Comment


          • #6
            Victoria:
            what if:
            Code:
            xi: xtscc  depvar  i.person  independentvar   i.person#c.independentvar
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Thanks Carlos. When I use 'xi' to naturally code the dummies as you suggest, I receive the error:
              Code:
              interactions not allowed
              Typically when I run xtscc, it will support factor variables, so a regression like
              Code:
              xtscc depvar i.person i.time
              works fine if I want to run something like a time and fixed effects regression. It seems like in this case, whether I use 'xi' or not, xtscc does not like interaction terms.
              The reason I am using this command is because I need the standard errors it produces. If there is an alternative where I can keep using this command but generating the interaction coefficients in a different manner, or perhaps some other option that will compute Driscoll-Kraay standard errors that someone might be aware of, that might be the route to take.
              Thanks again so far for your help!

              Comment


              • #8
                xtscc is from SSC (as you are asked to explain).

                xtscc does not like interaction terms.
                What do you mean by this? Have you checked if you have the latest version - update 1st December 2017? This works for me.

                Code:
                . webuse grunfeld
                
                . xtscc invest i.company##c.mvalue
                
                Regression with Driscoll-Kraay standard errors   Number of obs     =       200
                Method: Pooled OLS                               Number of groups  =        10
                Group variable (i): company                      F( 19,    19)     = 896288.91
                maximum lag: 2                                   Prob > F          =    0.0000
                                                                 R-squared         =    0.8617
                                                                 Root MSE          =   84.7882
                
                ----------------------------------------------------------------------------------
                                 |             Drisc/Kraay
                          invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                -----------------+----------------------------------------------------------------
                         company |
                              1  |          0  (empty)
                              2  |   404.9427   315.9457     1.28   0.215    -256.3393    1066.225
                              3  |   424.5293   310.8939     1.37   0.188    -226.1792    1075.238
                              4  |    379.444   339.9421     1.12   0.278    -332.0631    1090.951
                              5  |   417.4667   357.2834     1.17   0.257    -330.3361     1165.27
                              6  |   384.3755   355.9887     1.08   0.294    -360.7175    1129.469
                              7  |   427.6693   338.0704     1.27   0.221    -279.9202    1135.259
                              8  |   389.4019    358.159     1.09   0.291    -360.2334    1139.037
                              9  |    391.486     360.38     1.09   0.291     -362.798     1145.77
                             10  |   399.2205   359.8131     1.11   0.281     -353.877    1152.318
                                 |
                          mvalue |   .2314091    .094147     2.46   0.024     .0343572     .428461
                                 |
                company#c.mvalue |
                              1  |          0  (empty)
                              2  |  -.0283468   .0828177    -0.34   0.736    -.2016861    .1449926
                              3  |  -.1939956    .067089    -2.89   0.009    -.3344144   -.0535768
                              4  |  -.0849159   .0623267    -1.36   0.189    -.2153672    .0455354
                              5  |  -.0620275   .0926701    -0.67   0.511    -.2559883    .1319333
                              6  |  -.0744384   .0883096    -0.84   0.410    -.2592726    .1103958
                              7  |  -.1326228   .1280995    -1.04   0.314    -.4007382    .1354926
                              8  |   -.159327   .0938963    -1.70   0.106    -.3558544    .0372003
                              9  |  -.0957161   .1043904    -0.92   0.371    -.3142078    .1227755
                             10  |  -.2492454   .1192851    -2.09   0.050    -.4989119    .0004211
                                 |
                           _cons |   -394.871   358.2139    -1.10   0.284    -1144.621    354.8792
                ----------------------------------------------------------------------------------
                
                
                . which xtscc
                c:\ado\plus\x\xtscc.ado
                *! xtscc, version 1.4, Daniel Hoechle, 01dec2017

                Comment


                • #9
                  Andrew--I think you are correct. When I run a variation of my regression similar to what you have above, I can get some output. So, the error I am getting must not be because of the interaction term.
                  Once of my independent variables is the mean in each time period of the dependent variable. I am using it as the continuous variable in my interaction term, but I want to include it as a regressor by itself. So my regression would look like this:
                  Code:
                  xtscc dependentvar   i.person    mean_dependentvar  i.person#c.mean_dependentvar
                  but this is where Stata throws the error. It says that

                  Code:
                  _wmean_dependentvar invalid name
                  As I would like to include this variable on the right hand side as well as including it in the interaction term, I'm not sure what to do to remedy this error in stata. Thanks so far for your help!!

                  Comment


                  • #10
                    Sorry Victoria Consolvo, I missed this. I was offline for a couple of days. Do you generate the mean variable? Stata's syntax does not currently allow one to specify the mean of a variable directly. From a mechanics point of view, you should not have any problems getting results but there are issues with having the same variable on both the left and right hand side. Here is how you should go about it.

                    Code:
                    webuse grunfeld, clear
                    bys time: egen m_invest= mean(invest)
                    xtscc invest i.company##c.m_invest

                    Comment


                    • #11
                      Hi Andrew. Thanks for the input. I tried the code above and it definitely runs--however, when I try using the exact same set up for my specific data set and variables, it gives something akin to
                      Code:
                      _wm_invest invalid name
                      (except sub in the variable name I am using).
                      I can't figure out what is different about my mean variable (I am generating it the way you recommend) to be causing this issue. Thanks again for your thoughts so far. Much appreciated.

                      Comment


                      • #12
                        Thanks Andrew Musau. I realized it was a stupid error. My variable name was too long, so that's why I was getting an invalid name error. Shortening it and running your suggested code produces the results I need.
                        Many thanks for your help.

                        Comment


                        • #13
                          Thanks for the closure.

                          Comment


                          • #14
                            Hi Andrew, sorry seems like this issue has been discussed fairly recently but I am having the same problem of getting a message from Stata "c: operator invalid". As a matter of fact I used your example dataset and code above I am get "1b: operator invalid" message. I changed my version of xtscc and it's the lates i.e 1.4. Is it possible that Stata does not allow i.IV or c.IV anymore (I understand there has only been less than two months but the code xtscc invest i.company##c.mvalue does not run on Stata).

                            Thanks

                            Comment


                            • #15
                              This is the code and the results that I am getting

                              . webuse grunfeld

                              . tsset company year
                              panel variable: company (strongly balanced)
                              time variable: year, 1935 to 1954
                              delta: 1 year

                              xtscc invest i.company##c.mvalue

                              1b: operator invalid
                              r(198);

                              Comment

                              Working...
                              X