Announcement

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

  • Change label of interaction with esttab; matching coefficients (with dataex)

    Hi Statalist,

    I would like to make a regression table to import into LaTeX. The code below produces a regression table, but I would like to change two things:
    (1) I would like the coefficients for all the year ## reference group interactions to be matched by year. This is to make the table size smaller and make the coefficients easier to compare across reference groups.
    (2) Rather than the label being "ref=1 # year=YYYY" I'd like it to be something like "Reference # Year = YYYY" or even just "Year = YYYY" (since the reference group is defined in the first row).

    The blue in the code below is where I tried to make these changes below. The Dataex replicates the table. There are just some coefficients that are 0 because of the size of the dataex (the only one that should be 0 is 2015 because it's the reference year).

    Lastly, if there is a way to get the "Reference 1" centered above the columns (maybe with a line underneath), that would be an extra bonus!
    Thank you in advance

    Code:
    * Set as panel 
    xtset firmid year
    
    * Define locals 
    local indepvar indepvar1 indepvar2 
    local controls control1 control2 control3
    local reference  ref1 ref2 ref3
    
    * Run regression 
    eststo clear 
    foreach x in `reference'{
        foreach v in `indepvar'{
        eststo: reghdfe `v' `controls' ib0.`x'##ib2015.year, ///
                absorb(stnumbr) vce(cluster stnumbr#year)
        
        estadd local FE "YES"
        esttab, append rename("1.ref#year" "Reference") p label keep( `controls' 1.ref*#*year) varlabels("Year") mgroups("Reference 1" "Reference 2" "Reference 3", pattern(1 0 1 0 1 0))
        
        }
    }
    Code:
    clear
    input float(ref1 ref2 ref3 indepvar2 indepvar1 control2) double control3 float control1 long firmid float year byte stnumbr
    0 1 0  86081.51  11.36305         .                .049          . 458296 2021  4
    0 1 0 111239.84 11.619444         .                .049          . 194654 2021  4
    0 0 0  39690.41 10.588865 1.5938532  .06499999761581421  111282672 480429 2013  5
    0 0 0 286.56073   5.65795 1.5938532                .065  112687776 540035 2016  5
    0 0 0         0         . 1.5938532                .065  115400880 253550 2018  5
    0 0 0  92247.36  11.43223 1.2343913  .08839999884366989 2253082880  12980 2014  6
    0 0 0  60902.95 11.017037 1.2343913               .0884 2362754304 464235 2015  6
    0 0 0  32637.66 10.393222 1.2343913               .0884 2430218496 542081 2016  6
    0 0 0 28027.205  10.24093 1.2343913               .0884 2534740736 557633 2017  6
    0 0 0 268514.06  12.50066  1.600829               .0884 2624353024 295004 2018  6
    0 0 0 183761.77 12.121395         .               .0884 2646403584 256109 2020  6
    0 0 0  91388.29 11.422873 1.3810716               .0463  312012384 256628 2016  8
    0 1 0   35164.5 10.467793  .8827389  .09000000357627869  237369408  12141 2013  9
    0 1 0 34846.023 10.458694  .8827389               .0825  254441888 264804 2018  9
    0 1 0 12133.243  9.403705  .8827389               .0825  254441888 535277 2018  9
    1 0 0  40315.11 10.604482 2.0332832 .054999999701976776  821712256 241676 2014 12
    1 0 0 136918.34  11.82714 2.0332832                .055  901628416 250792 2016 12
    1 0 0  60406.85 11.008858         .                .055  994240768 466557 2019 12
    1 0 0  45929.19 10.734856         .                .055  994240768 287720 2019 12
    1 0 0  56179.41 10.936306         .                .055  994240768 246815 2019 12
    1 0 0 104877.98 11.560553         .              .04458  973340096 444321 2020 12
    1 0 0 27887.145  10.23592         .              .04458  973340096 604908 2020 12
    0 0 0  30110.81  10.31264 1.3065344  .05999999865889549  456770752 432364 2013 13
    0 0 0   40802.3 10.616493         .               .0575  567991168   7676 2019 13
    0 0 0  266260.7  12.49223         .               .0575  547928704   7448 2020 13
    0 0 0 15478.802  9.647226         .               .0575          . 252615 2021 13
    0 0 0 25857.416 10.160353 1.0313817                .074   62947980 287013 2015 16
    0 0 0         0         . 1.5584137               .0775  767645952 201848 2017 17
    0 0 0  41699.71  10.63825 1.5584137               .0775  767645952 454208 2017 17
    0 0 0  834833.8 13.634988         .                .095  793021760  10604 2019 17
    0 0 0  26003.15 10.165973         .                .095  793021760 220398 2019 17
    0 0 0  41916.52 10.643435         .                .095  755385216 522023 2020 17
    0 0 0  92758.73 11.437757         .                .095          .  15429 2021 17
    0 0 0  6393.191  8.762989 1.6634413                 .07  317076352 500317 2015 18
    0 0 0 29956.297 10.307495         .               .0575  339317376 263207 2019 18
    0 0 0  68450.99 11.133873  1.435794                 .12  172222864 223071 2015 19
    0 0 0 17414.354   9.76505  1.435794                 .12  172222864 281320 2015 19
    0 0 0 13678.793  9.523602  2.329555                 .06  188774848 222463 2018 21
    0 0 0  33010.61 10.404584  .8120924  .07999999821186066  232263152 262882 2014 22
    0 0 0         0         .  1.587803               .0825  366696928 525923 2016 24
    0 0 0 22440.797 10.018636         .               .0825          . 362711 2021 24
    0 0 0 77899.234  11.26317  1.684894                 .08  494102144 243095 2017 25
    0 0 0  58339.57 10.974036         .                 .08  512594784 467458 2020 25
    0 0 0  59747.16 10.997877 1.9818847                 .06  453706752 187314 2015 26
    0 0 0  46027.67 10.736998 .54936564  .09799999743700027  305782816   3419 2013 27
    0 0 0  43754.39 10.686347 .54936564  .09799999743700027  305782816 289375 2013 27
    0 0 0 34098.902  10.43702 .54936564  .09799999743700027  313319904 424309 2014 27
    0 0 0 206368.47 12.237418 1.8595614                 .05  101894560  13249 2018 28
    0 0 0  9986.619  9.209002         .                 .05  102176136 441495 2019 28
    0 0 0  51024.02 10.840052         .                 .05  102176136 206369 2019 28
    0 0 0  22441.64 10.018674         .                 .05          . 493043 2021 28
    0 0 0         0         .  2.388279               .0625  284588384 241451 2016 29
    0 0 0 182030.38  12.11193  2.388279               .0625  289524384  13289 2018 29
    0 0 0  53358.14 10.884782  1.707234               .0675   44958848 445290 2017 30
    0 0 0  74972.05  11.22487 1.5783843               .0781  111735904 440213 2016 31
    0 0 0 13416.546  9.504244  .9419047  .09000000357627869  525003328 227360 2013 34
    0 0 0  70997.57   11.1704  .9419047                 .09  538004096  41982 2015 34
    0 0 0  82277.62 11.317854  1.881553                 .09  556133760 182010 2018 34
    0 0 0  61011.02  11.01881 1.3440464  .07100000232458115 1380553856 190490 2014 36
    0 0 0  83186.93 11.328846 1.3440464  .07100000232458115 1380553856 494163 2014 36
    0 0 0  70873.19 11.168648 1.3440464                .065 1467185408   8183 2016 36
    0 0 0   79071.4 11.278107 1.3440464                .065 1536446464 213651 2018 36
    0 0 0  233926.1  12.36276         .                .065          . 236789 2021 36
    0 0 1 156860720 18.870869 1.9964814   .0689999982714653  454329504   2238 2013 37
    0 0 1  39180.61 10.575937         .                .025  530460448 474344 2019 37
    0 0 1  25710.84 10.154668         .                .025  519064928 496430 2020 37
    0 0 1 36694.336 10.510378 2.0727897               .0431   53566332   7361 2018 38
    0 1 0   41682.6  10.63784  2.182695                   0  556802240 248957 2013 39
    0 1 0  79882.06 11.288306  2.182695                   0  556802240 210934 2013 39
    0 1 0  52436.43 10.867357         .                   0  617328128  43065 2019 39
    0 1 0  54226.32 10.900922         .                   0  596271488   4415 2020 39
    0 1 0  43544.57  10.68154         .                   0  596271488 211711 2020 39
    0 0 0  7965.116  8.982827         .                 .06  165494720 466058 2020 40
    0 0 0    190553 12.157685 1.8257158               .0999  682210624 184657 2015 42
    0 0 0  51499.68  10.84933         .               .0999          . 185616 2021 42
    0 0 0  33855.12 10.429846         .                 .05  217883824 191266 2019 45
    0 0 0 107076.64   11.5813  2.461989                .065  310722688 540787 2015 47
    0 0 0 23343.314 10.058066  2.461989                .065  310722688 359422 2015 47
    0 0 0 35545.383 10.478565         .                .065  335662688 260542 2019 47
    0 0 1   826.833  6.717603 1.4675543                   0 1523707136 521668 2014 48
    0 0 1  29374.84 10.287894 1.6427464                   0 1493345408 443242 2016 48
    0 0 1 24663.525  10.11308 1.6427464                   0 1640463872 259217 2018 48
    0 0 1  31097.09  10.34487         .                   0 1659942656 494094 2019 48
    0 0 1   4786908 15.381395         .                   0 1562563584   2108 2020 48
    0 0 1 114494.03 11.648278         .                   0 1562563584 447243 2020 48
    0 0 1  91596.01 11.425143         .                   0          . 463773 2021 48
    0 0 0 31978.273 10.372812  1.730747  .05000000074505806  137146336 229920 2014 49
    0 0 0  4626.297  8.439512         .               .0495  173859648 490974 2020 49
    0 0 0  63570.63 11.059907  1.969881  .05999999865889549  448807072 208878 2014 51
    0 0 0  59502.62 10.993775  1.969881                 .06  462115552 453294 2015 51
    0 0 0 18123.115  9.804943  1.969881                 .06  462115552 470792 2015 51
    0 0 0  5798.363  8.665331  1.969881                 .06  469109504 445179 2016 51
    0 0 0  70085.38  11.15747  1.969881                 .06  469109504 227609 2016 51
    0 0 0 74343.945 11.216457         .                 .06  493636672 447851 2019 51
    0 0 0  83791.68  11.33609         .                   0  531759104 261837 2020 53
    0 0 0 26509.904 10.185274         .                .065   66754364 285555 2020 54
    0 1 0   43136.2 10.672118 2.2548711  .07900000363588333  279388544 277503 2013 55
    0 1 0 18607.533  9.831322 2.2548711                .079  297033216 220320 2016 55
    0 1 0  29091.12 10.278188 2.2548711                .079  297033216 273774 2016 55
    0 1 0 21287.014  9.965853 2.2548711                .079  295488256 277587 2017 55
    end


Working...
X