Announcement

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

  • Manually created interaction term and ## command

    Hi,
    this is my first time using Stata.
    I would like to include an interaction term in my model:

    Code:
    egen voc = group(vis)
    Code:
    xtreg foreign_revenues state_dom##voc state_min##voc log_age log_asset log_gdp_capita i.sector i.year, robust
    where state_dom and state_min are dummy variables and voc is 4 different groups.

    Can anyone tell me how to implement the same xtreg function manually creating interaction term instead of ##?

    Thanks very much

  • #2
    Mark:
    welcom to this forum.
    Strange question indeed (usually, details about the opposite approach are requested).
    Anyway, you may want to replace your code with the following one:
    Code:
    xtreg voc foreign_revenues state_dom foreign_revenues state_dom*voc state_min state_min*voc log_age log_asset log_gdp_capita i.sector i.year, robust
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      I'm sorry, I'd have posted the whole code:
      Code:
       
       gen state_dom = 0  replace state_dom=1 if state_ownership>=25  gen state_min = 0  replace state_min=1 if state_ownership<25 & state_ownership>0  egen voc = group(vis) //CME=1, Emergent LME=2, Hierarchically Coordinated=3, State Led=4.  gen statedomCME = 0 gen statedomELME = 0 gen statedomHC = 0 gen statedomSL = 0 replace statedomCME = state_dom*voc if voc==1 replace statedomELME = state_dom*voc if voc==2 replace statedomHC = state_dom*voc if voc==3 replace statedomSL = state_dom*voc if voc==4  xtset id_company year //definisco un binomial panel NxT  xtreg foreign_revenues state_dom##voc log_age log_asset log_gdp_capita i.sector i.year, robust  xtreg foreign_revenues state_dom i.voc statedomCME statedomELME statedomHC statedomSL log_age log_asset log_gdp_capita i.sector i.year, robust
      Why do I get different results for the two xtreg commands?

      Comment


      • #4
        What I want to know is how I can implement the first xtreg instruction using manually created variable instead of using ##

        Comment


        • #5
          Mark:
          from
          definisco un binomial panel
          I would say that your probably not English mother-tongue.
          Please note that Stata community appreciates real given and family names (for reasons that are well explained in FAQ).
          That said, you would increase your chances of getting helpful replies if you posted a readable code (copy and paste from a do-file is a good approach) and share not only what you typed, but what Stata gave you back (ie, outcome tables), too.
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            I'm from Italy and that's my real name.

            gen state_dom = 0
            replace state_dom=1 if state_ownership>=25
            gen state_min = 0
            replace state_min=1 if state_ownership<25 & state_ownership>0

            egen voc = group(vis) //CME=1, Emergent LME=2, Hierarchically Coordinated=3, State Led=4

            gen statedomCME = 0
            gen statedomELME = 0
            gen statedomHC = 0
            gen statedomSL = 0
            replace statedomCME = state_dom*voc if voc==1
            replace statedomELME = state_dom*voc if voc==2
            replace statedomHC = state_dom*voc if voc==3
            replace statedomSL = state_dom*voc if voc==4

            xtset id_company year

            xtreg foreign_revenues state_dom##voc log_age log_asset log_gdp_capita i.sector i.year, robust
            xtreg foreign_revenues state_dom i.voc statedomELME statedomHC statedomSL log_age log_asset log_gdp_capita i.sector i.year, robust


            What I'd like to know is how I can implement the first xtreg instruction using manually created variable instead of using ##

            Random-effects GLS regression Number of obs = 1450
            Group variable: id_company Number of groups = 145

            R-sq: within = 0.0845 Obs per group: min = 10
            between = 0.3117 avg = 10.0
            overall = 0.2956 max = 10

            Wald chi2(28) = 234.04
            corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000

            (Std. Err. adjusted for 145 clusters in id_company)

            Robust
            foreign_reve~s Coef. Std. Err. z P>z [95% Conf. Interval]

            1.state_dom -.0171317 .0199518 -0.86 0.391 -.0562366 .0219731

            voc
            2 .1701311 .100678 1.69 0.091 -.0271941 .3674564
            3 .1191134 .0910838 1.31 0.191 -.0594076 .2976343
            4 -.0505043 .1084388 -0.47 0.641 -.2630405 .1620319

            state_dom#voc
            1 2 .1275343 .0299164 4.26 0.000 .0688992 .1861694
            1 3 .0250271 .0373816 0.67 0.503 -.0482395 .0982936
            1 4 -.0776619 .0588236 -1.32 0.187 -.1929541 .0376304

            log_age .0283696 .0381954 0.74 0.458 -.046492 .1032311
            log_asset .102811 .0618559 1.66 0.096 -.0184244 .2240464
            log_gdp_capita -.065378 .039678 -1.65 0.099 -.1431453 .0123894

            sector
            2 .3483784 .1328379 2.62 0.009 .0880209 .6087359
            3 -.1213994 .0706451 -1.72 0.086 -.2598613 .0170626
            4 .0783069 .1183086 0.66 0.508 -.1535738 .3101875
            5 .4735978 .0767551 6.17 0.000 .3231607 .624035
            6 .1200187 .0683085 1.76 0.079 -.0138634 .2539008
            7 -.0488898 .0809016 -0.60 0.546 -.2074539 .1096744
            8 -.0078801 .1304892 -0.06 0.952 -.2636343 .247874
            9 -.1194326 .057179 -2.09 0.037 -.2315014 -.0073638
            10 .2788296 .094348 2.96 0.003 .0939108 .4637483

            year
            2009 -.0099008 .0050901 -1.95 0.052 -.0198771 .0000756
            2010 -.0028758 .0113268 -0.25 0.800 -.025076 .0193244
            2011 .0017951 .0135426 0.13 0.895 -.0247478 .028338
            2012 .0060339 .0148849 0.41 0.685 -.02314 .0352078
            2013 .0165934 .0167894 0.99 0.323 -.0163131 .0495
            2014 .0274765 .0176467 1.56 0.119 -.0071105 .0620634
            2015 .0293138 .016608 1.77 0.078 -.0032373 .0618649
            2016 .0265384 .0174468 1.52 0.128 -.0076567 .0607335
            2017 .0246151 .0190346 1.29 0.196 -.0126919 .0619222

            _cons -.306811 .5414033 -0.57 0.571 -1.367942 .7543199

            sigma_u .23393536
            sigma_e .08043675
            rho .89427267 (fraction of variance due to u_i)





            Random-effects GLS regression Number of obs = 1450
            Group variable: id_company Number of groups = 145

            R-sq: within = 0.0845 Obs per group: min = 10
            between = 0.3117 avg = 10.0
            overall = 0.2956 max = 10

            Wald chi2(28) = 234.04
            corr(u_i, X) = 0 (assumed) Prob > chi2 = 0.0000

            (Std. Err. adjusted for 145 clusters in id_company)

            Robust
            foreign_reve~s Coef. Std. Err. z P>z [95% Conf. Interval]

            state_dom -.0171317 .0199518 -0.86 0.391 -.0562366 .0219731

            voc
            2 .1701311 .100678 1.69 0.091 -.0271941 .3674564
            3 .1191134 .0910838 1.31 0.191 -.0594076 .2976343
            4 -.0505043 .1084388 -0.47 0.641 -.2630405 .1620319

            statedomELME .0637672 .0149582 4.26 0.000 .0344496 .0930847
            statedomHC .0083424 .0124605 0.67 0.503 -.0160798 .0327645
            statedomSL -.0194155 .0147059 -1.32 0.187 -.0482385 .0094076
            log_age .0283696 .0381954 0.74 0.458 -.046492 .1032311
            log_asset .102811 .0618559 1.66 0.096 -.0184244 .2240464
            log_gdp_capita -.065378 .039678 -1.65 0.099 -.1431453 .0123894

            sector
            2 .3483784 .1328379 2.62 0.009 .0880209 .6087359
            3 -.1213994 .0706451 -1.72 0.086 -.2598613 .0170626
            4 .0783069 .1183086 0.66 0.508 -.1535738 .3101875
            5 .4735978 .0767551 6.17 0.000 .3231607 .624035
            6 .1200187 .0683085 1.76 0.079 -.0138634 .2539008
            7 -.0488898 .0809016 -0.60 0.546 -.2074539 .1096744
            8 -.0078801 .1304892 -0.06 0.952 -.2636343 .247874
            9 -.1194326 .057179 -2.09 0.037 -.2315014 -.0073638
            10 .2788296 .094348 2.96 0.003 .0939108 .4637483

            year
            2009 -.0099008 .0050901 -1.95 0.052 -.0198771 .0000756
            2010 -.0028758 .0113268 -0.25 0.800 -.025076 .0193244
            2011 .0017951 .0135426 0.13 0.895 -.0247478 .028338
            2012 .0060339 .0148849 0.41 0.685 -.02314 .0352078
            2013 .0165934 .0167894 0.99 0.323 -.0163131 .0495
            2014 .0274765 .0176467 1.56 0.119 -.0071105 .0620634
            2015 .0293138 .016608 1.77 0.078 -.0032373 .0618649
            2016 .0265384 .0174468 1.52 0.128 -.0076567 .0607335
            2017 .0246151 .0190346 1.29 0.196 -.0126919 .0619222

            _cons -.306811 .5414033 -0.57 0.571 -1.367942 .7543199

            sigma_u .23393536
            sigma_e .08043675
            rho .89427267 (fraction of variance due to u_i)


            Comment


            • #7
              Code:
              xtreg foreign_revenues state_dom voc state_dom*voc log_age log_asset log_gdp_capita i.sector i.year, robust
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #8
                Carlo's codes in #2 and #7 will not work. Even if we add the (old) xi prefix, the code will not produce the intended results.

                Here are two ways of doing what Mark wants to (but should probably not) do:

                Code:
                xi : xtreg ... i.state_dom*i.voc i.state_min*i.voc
                Code:
                egen state_dom_voc = group(state_dom voc) , label
                egen state_min_voc = group(state_min voc) , label
                xtreg ... i.state_dom_voc i.state_min_voc
                Either way, Mark will not obtain correct results from margins and possibly other post-estimation commands and there really is no reason to want to create the interactions by hand.


                Added in Edit:


                Reading

                Code:
                gen state_dom = 0
                replace state_dom=1 if state_ownership>=25
                gen state_min = 0
                replace state_min=1 if state_ownership<25 & state_ownership>0
                from #6 is puzzling. If state_ownership has missing values, then those will be coded 1 in state_dom which is probably not what Mark wants. Also, even if the two variables are correctly created, they seem to be collinear; including both in one model does not make sense.

                There might be more problems, I did not read through the whole code.

                Best
                Daniel
                Last edited by daniel klein; 04 Jun 2019, 04:12.

                Comment


                • #9
                  Cross-posted at https://stackoverflow.com/questions/...eraction-terms

                  Please note our cross-posting policy, explicit in the FAQ Advice you were asked to read before posting: You are asked to tell us about it.

                  Comment

                  Working...
                  X