Announcement

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

  • Difference and Its Confidence Interval of Marginal Effects Across Models

    Hello!

    I am seeking for help with my data analysis. I am having a hard time getting a difference in marginal effects of an independent variable in two different models (same right-hand side variables and different outcome variables) in Stata. My data is an unbalanced panel (example data shown below) and the two models have two interaction terms. I am estimating marginal effects of a categorical variable (consisting one interaction term) in two different models and want to know the difference and its confident intervals of those marginal effects. The following shows some of my codes.

    Code:
    reghdfe pov c.ER##i.grecession c.ER##i.covid hhchildren hage hhigh i.famempsingle  i.disability  if singleheaded==1 & hfemale==1 [pw=lweight] ,absorb(id state) vce(cluster state)
    
    margins, dydx(grecession)
    
    reghdfe pov_nossdi c.ER##i.grecession c.ER##i.covid hhchildren hage hhigh i.famempsingle  i.disability  if singleheaded==1 & hfemale==1 [pw=lweight] ,absorb(id state) vce(cluster state)
    
    margins, dydx(grecession)

    Then, I want to compare the marginal effects of grecession from the two models.

    I've tried to search the Internet on this topic, but can't find the solution. I know the Stata command "suest" can compare coefficients/marginal effects of a variable across models. But this doesn't support my regression command, "reghdfe." I'm wondering if there is any way (manually or by user written commands) to estimate the difference in marginal effects across models when using reghdfe. I really appreciate your help in advance!

    Thank you very much,
    Hyun Ju





    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(pov pov_nossdi ER grecession covid hhchildren hage hhigh famempsingle disability singleheaded hfemale lweight id state)
    0 0 .625 0 0 1 35 1 . 0 0 0 18.149  6523 34
    0 0 .641 0 0 1 29 1 . 0 0 0 23.885  6792 27
    0 0 .633 0 0 1 29 1 2 0 1 1      . 10749 42
    1 1 .573 0 0 1 48 0 2 0 1 1      . 13509 17
    0 0 .633 0 0 1 50 0 . 0 0 0 53.976   207 42
    0 0 .687 0 0 1 26 1 1 0 1 0  13.78  1811  5
    0 0 .643 0 0 0 40 0 1 0 1 0  7.323  5052 10
    0 0 .626 0 0 0 54 0 . 1 0 0  7.631  5506 32
    1 1  .61 0 0 0 45 1 2 1 1 1  9.106  1459 21
    0 0 .578 0 0 1 25 0 . 0 0 0 16.546  4869 23
    0 0 .635 0 0 1 27 0 1 1 1 0      . 14692 13
    0 0 .709 0 0 1 43 1 . 0 0 0 40.491  3703 22
    0 0 .615 0 0 0 52 1 1 0 1 0 73.918   287  4
    0 0 .643 0 0 1 45 1 . 0 0 0 39.177  2855 24
    1 1 .615 0 0 1 46 0 . 1 0 0 31.684  5441  4
    0 0 .633 0 0 1 26 0 1 0 1 1      .  9985 42
    0 0 .678 0 0 0 52 1 . 0 0 0 34.157   392 14
    0 0 .592 0 0 1 48 1 . 0 0 0      . 15882  9
    0 0 .623 0 0 0 38 1 1 0 1 1  9.204  6526 12
    0 0 .586 0 0 1 47 1 1 0 1 1      . 16061 16
    0 0 .595 0 0 1 43 1 . 0 0 0 30.459  2661 39
    0 0 .651 0 0 0 54 1 1 1 1 1      . 10733 45
    0 0 .635 0 0 1 47 1 . 0 0 0 32.413  2763 13
    1 1 .615 0 0 0 34 1 1 0 1 0      . 15516  4
    1 1 .641 0 0 1 47 1 . 0 0 0 50.092   124 27
    0 0 .626 0 0 0 43 0 1 1 1 1 22.186  2966 29
    0 0 .643 0 0 1 32 1 . 0 0 0 53.835    51 10
    0 0 .615 0 0 0 53 1 . 1 0 0 41.151  4838  4
    0 0 .573 0 0 1 39 0 . 0 0 0  18.12  3444 17
    0 0 .609 0 0 0 42 0 . 1 0 0   6.16  3919 37
    0 0 .592 0 0 1 45 1 . 1 0 0      . 11416  9
    1 1 .616 0 0 1 26 1 1 0 1 1      .  9214  2
    0 0 .712 0 0 0 50 1 . 0 0 0 30.828  5452 26
    0 0 .615 0 0 0 49 1 1 0 1 0 11.629  3439  4
    0 0 .609 0 0 0 21 0 2 0 1 0  3.779  6729 37
    0 0 .592 0 0 0 52 1 . 0 0 0 52.217  4380  9
    0 0 .592 0 0 1 37 1 1 0 1 0      . 12930  9
    0 0 .615 0 0 1 33 1 1 0 1 1      . 15368  4
    0 0 .625 0 0 0 48 1 1 0 1 0      . 12784 34
    0 0  .61 0 0 1 41 1 . 0 0 0 24.893  6288 21
    0 0 .591 0 0 0 53 1 . 1 0 0 48.814  1771 31
    0 0 .676 0 0 0 38 1 . 0 0 0      . 10303 43
    0 0 .641 0 0 0 50 1 . 0 0 0 33.533  2778 27
    0 0 .615 0 0 1 35 0 . 0 0 0 19.099  4800  4
    1 1 .615 0 0 1 36 0 3 0 1 0      .  9764  4
    0 0 .643 0 0 0 55 1 . 0 0 0 31.629  4473 24
    1 1 .654 0 0 1 33 0 . 0 1 1      . 14796 19
    0 0 .578 0 0 1 24 1 3 0 1 1  1.976  6801 23
    1 1 .626 0 0 1 53 0 3 0 1 1 12.704  6492 32
    0 0  .64 0 0 1 54 1 . 0 0 0  59.15   844 20
    0 0 .683 0 0 0 33 1 . 0 0 0 27.814   458 28
    0 0 .623 0 0 0 33 1 1 0 1 0      . 15747 12
    0 0 .609 0 0 1 32 0 1 1 1 1      . 11648 37
    0 0 .641 0 0 0 46 1 1 0 1 1 37.142  5462 27
    0 0 .631 0 0 0 24 1 . 0 0 0 27.657   908 46
    0 0 .635 0 0 1 53 1 . 1 0 0      . 10517 13
    0 0 .615 0 0 1 30 0 1 0 1 0      . 13929  4
    1 1 .633 0 0 0 58 0 3 1 1 0      . 15538 42
    0 0 .623 0 0 0 20 1 1 0 1 0      .  9298 12
    0 0 .654 0 0 1 34 1 1 0 1 0      . 15731 19
    0 0 .626 0 0 1 25 1 . 0 0 0 11.984  3536 32
    0 0 .654 0 0 1 33 1 . 0 0 0      . 12181 19
    0 0 .643 0 0 0 43 1 . 1 0 0 26.846  6422 24
    0 0 .615 0 0 1 32 1 1 0 1 1  4.317  1818  4
    0 0 .586 0 0 1 52 1 1 0 1 1      .  9422  1
    0 0 .586 0 0 1 40 1 . 0 0 0      . 15549 16
    0 0 .578 0 0 1 28 0 1 0 1 0   .852  5465 23
    0 0 .592 0 0 0 25 1 1 0 1 1      . 15387  9
    0 0 .591 0 0 1 45 0 . 1 0 0 32.569   457 31
    0 0 .632 0 0 0 48 1 . 0 0 0 31.643  6922 18
    1 1 .626 0 0 0 48 1 2 0 1 1  8.407  2804 32
    0 0 .626 0 0 1 55 1 1 1 1 1 18.179  7869 29
    0 0 .651 0 0 0 44 1 1 0 1 0 51.878  8137 45
    0 0 .626 0 0 1 33 1 . 0 0 0 20.294  3631 32
    0 0 .635 0 0 0 64 0 3 0 1 1 27.464  2728 13
    0 0 .643 0 0 1 30 1 . 0 0 0      . 13773 10
    0 0 .631 0 0 0 27 1 . 0 0 0      . 15265 46
    0 0 .615 0 0 1 31 1 . 1 0 0 33.897  8255  4
    0 0 .625 0 0 0 64 1 . 1 0 0 70.489  8943 34
    0 0 .633 0 0 0 49 1 1 0 1 1      . 10902 42
    0 0 .654 0 0 1 35 1 1 0 1 1 15.461  6037 19
    0 0  .64 0 0 0 42 1 1 0 1 0 32.748  5644 20
    0 0 .586 0 0 0 29 1 2 0 1 1      . 15170  1
    0 0 .631 0 0 1 31 1 3 1 1 0      . 12391 46
    0 0 .676 0 0 0 62 1 . 1 0 0      .  9427 43
    0 0 .615 0 0 0 53 0 . 0 0 0 35.916   486  4
    1 1 .578 0 0 1 26 0 1 0 1 1  2.392  8177 23
    0 0 .595 0 0 1 36 1 . 1 0 0   4.38  6721 39
    0 0 .616 0 0 1 34 1 . 0 0 0      . 14997  2
    0 0 .687 0 0 0 26 1 2 0 1 0 17.311  7571  5
    0 0  .61 0 0 0 55 1 . 0 0 0  40.95   352 21
    0 0 .651 0 0 0 54 1 . 0 0 0      . 15864 45
    1 1 .622 0 0 0 44 1 . 0 1 0  3.475  2213  8
    1 1 .578 0 0 0 53 1 1 0 1 1 10.415  2817 23
    0 0 .589 0 0 1 34 1 . 1 0 0 47.969   615  3
    0 0 .679 0 0 1 40 1 . 1 0 0 31.509  2291 48
    0 0 .595 0 0 1 54 1 . 0 0 0 32.628  6764 39
    0 0 .609 0 0 1 51 0 . 1 0 0      . 14449 37
    0 0 .609 0 0 0 50 0 1 1 1 1      .  9430 37
    0 0 .591 0 0 1 47 0 . 0 0 0 41.011  8399 31
    end
    label values pov pov
    label def pov 0 "Not in poverty", modify
    label def pov 1 "In poverty", modify
    label values hfemale yesno
    label values hhchildren yesno
    label values disability yesno
    label def yesno 0 "no", modify
    label def yesno 1 "yes", modify
    label values hhigh highschool
    label def highschool 0 "Less than high school", modify
    label def highschool 1 "High school or higher", modify
    label values famempsingle famempsingle
    label def famempsingle 1 "Full time working", modify
    label def famempsingle 2 "Part time working", modify
    label def famempsingle 3 "Not working", modify

  • #2
    perhaps what i have here may help
    https://friosavila.github.io/chatgpt...023/index.html

    Comment


    • #3
      Try this. I filter out the FE and use reg.

      Code:
      ssc install hdfe, replace
      sysuse auto, clear
      
      eststo e1: reghdfe price weight mpg length, absorb(rep78 foreign) cluster(rep78)
      eststo e2: reghdfe displacement weight mpg length, absorb(rep78 foreign) cluster(rep78)
      
      hdfe price displacement weight mpg length , absorb(rep78 foreign) generate(fe)
      
      eststo f1: reg feprice feweight fempg felength , cluster(rep78)
      eststo f2: reg fedisplacement feweight fempg felength, cluster(rep78)
      
      esttab e1 f1 e2 f2
      
      eststo s1: reg feprice feweight fempg felength
      eststo s2: reg fedisplacement feweight fempg felength
      
      suest s1 s2, cluster(rep78)
      Last edited by George Ford; 14 Dec 2023, 10:03.

      Comment


      • #4
        George Ford Thank you so much for the codes. I tried it with mine including the interaction terms, but at "hdfe" stage, I got an error: there are repeated variables: <ER>. Do you recommend other ways to include interaction terms? Thank you so much.

        Comment


        • #5
          leave out the interactions at hdfe.

          it's just centering everything.

          Comment


          • #6
            George Ford Thanks. I ran the following codes without interaction terms in hdfe and got some results. I'm still having a hard time understanding what the results mean though... I just want to know whether the marginal effects of grecession in different models significantly different. In the final result table (shown below) after suest s1 s2, cluster(state), which estimate would mean what I'm looking for? I'm also not sure if I ran correct commands with interaction terms at the beginning. Thank you for your help!



            Code:
            eststo e1: reghdfe pov c.ER##i.grecession c.ER##i.covid hhchildren hage hhigh i.famempsingle  i.disability  if singleheaded==1 & hfemale==1 [pw=lweight] ,absorb(id state) vce(cluster state)
            eststo e2: reghdfe pov_nossdi c.ER##i.grecession c.ER##i.covid hhchildren hage hhigh i.famempsingle  i.disability  if singleheaded==1 & hfemale==1 [pw=lweight] ,absorb(id state) vce(cluster state)
            
            hdfe pov pov_nossdi ER grecession covid hhchildren hage hhigh i.famempsingle  i.disability  if singleheaded==1 & hfemale==1 [pw=lweight] ,absorb(id state) gen(fe)
            
            eststo f1: reg fepov feER fegrecession fecovid fehhchildren fehage fehhigh fe__2__famempsingle fe__3__famempsingle fe__1__disability, cluster(state)
            eststo f2: reg fepov_nossdi feER fegrecession fecovid fehhchildren fehage fehhigh fe__2__famempsingle fe__3__famempsingle fe__1__disability, cluster(state)
            
            esttab e1 f1 e2 f2
            
            eststo s1: reg fepov feER fegrecession fecovid fehhchildren fehage fehhigh fe__2__famempsingle fe__3__famempsingle fe__1__disability
            eststo s2: reg fepov_nossdi feER fegrecession fecovid fehhchildren fehage fehhigh fe__2__famempsingle fe__3__famempsingle fe__1__disability
            
            suest s1 s2, cluster(state)
            
            Simultaneous results for s1, s2                         Number of obs = 12,109
            
                                                    (Std. err. adjusted for 49 clusters in state)
            -------------------------------------------------------------------------------------
                                |               Robust
                                | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
            --------------------+----------------------------------------------------------------
            s1_mean             |
                           feER |  -.7210875   .2166264    -3.33   0.001    -1.145667   -.2965077
                   fegrecession |    .009386   .0094491     0.99   0.321    -.0091339    .0279058
                        fecovid |   .0186678    .020826     0.90   0.370    -.0221505    .0594861
                   fehhchildren |   .0281047   .0114292     2.46   0.014     .0057039    .0505054
                         fehage |  -.0067178   .0009391    -7.15   0.000    -.0085584   -.0048772
                        fehhigh |  -.0852299   .0245674    -3.47   0.001     -.133381   -.0370787
            fe__2__famempsingle |   .1694075   .0110499    15.33   0.000       .14775    .1910649
            fe__3__famempsingle |   .1881459   .0141708    13.28   0.000     .1603716    .2159202
              fe__1__disability |   .0288071   .0077528     3.72   0.000     .0136119    .0440024
                          _cons |   3.79e-11   .0009649     0.00   1.000    -.0018912    .0018912
            --------------------+----------------------------------------------------------------
            s1_lnvar            |
                          _cons |  -2.496579   .0388769   -64.22   0.000    -2.572776   -2.420381
            --------------------+----------------------------------------------------------------
            s2_mean             |
                           feER |  -.8870147   .2026619    -4.38   0.000    -1.284225   -.4898047
                   fegrecession |   .0084585   .0073067     1.16   0.247    -.0058623    .0227793
                        fecovid |   .0278657   .0201141     1.39   0.166    -.0115572    .0672886
                   fehhchildren |   .0226487   .0101497     2.23   0.026     .0027557    .0425417
                         fehage |  -.0036471   .0009268    -3.94   0.000    -.0054635   -.0018307
                        fehhigh |   -.083285   .0283001    -2.94   0.003    -.1387522   -.0278179
            fe__2__famempsingle |   .1853784   .0116469    15.92   0.000     .1625509    .2082059
            fe__3__famempsingle |   .2138694    .014629    14.62   0.000     .1851971    .2425417
              fe__1__disability |   .0456749   .0093726     4.87   0.000     .0273048    .0640449
                          _cons |  -2.51e-11   .0008803    -0.00   1.000    -.0017254    .0017254
            --------------------+----------------------------------------------------------------
            s2_lnvar            |
                          _cons |   -2.49954   .0367424   -68.03   0.000    -2.571554   -2.427527

            Comment


            • #7
              You can use the interactions in the final model. After suest, you can get test the coefficients between equations.

              Absent the interactions,

              Code:
              lincom [s1_mean]fegerecession - [s2_mean]fegerecession
              It's a little more complex with the interactions.

              Comment


              • #8
                George Ford Thanks very much! So do I add interactions at eststo s1 and eststo s2? For example,

                Code:
                eststo s1: reg fepov c.feER##i.fegrecession c.feER##i.fecovid fehhchildren fehage fehhigh fe__2__famempsingle fe__3__famempsingle fe__1__disability
                
                eststo s2: reg fepov_nossdi c.feER##i.fegrecession c.feER##i.fecovid fehhchildren fehage fehhigh fe__2__famempsingle fe__3__famempsingle fe__1__disability

                I did get a test estimation after running your lincom code, without adding interaction terms in the final model.


                Code:
                lincom [s1_mean]fegrecession - [s2_mean]fegrecession
                
                 ( 1)  [s1_mean]fegrecession - [s2_mean]fegrecession = 0
                
                ------------------------------------------------------------------------------
                             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
                -------------+----------------------------------------------------------------
                         (1) |   .0009274    .005836     0.16   0.874    -.0105109    .0123658
                ------------------------------------------------------------------------------
                Thank you again!

                Comment

                Working...
                X