Announcement

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

  • insert page break when appending output into a .tex file with -esttab-

    Dear all,

    a question on a general problem with no specific reference to particular data.

    Suppose you're running regressions in a loop and want to export results using eststo and esttab (ssc des estout) within the loop. You aim for a single tex-formatted pdf file containing the many tables, so you use append and tex (or booktabs or fagment). Is there any (even better, a quick and easy) way to introduce a page break in the tex file, after the code of each table is appended?

    It's not clear to me that longtable or width() can help - but I rarely use LaTex and happy to be corrected. I also saw tex3pt (ssc des tex3pt) which seems to have been written pecisely to improve the esttab-to-tex path, but I can't make it work within the very same loop producing regressions, as it seems to me that options required to introduce LaTex code to initialize and eventually close a document, on the one hand, and the clearpage option to introduce the page break cannot be used in the same instance of the command - and the help file exemplifies multiple tables by running the command twice, with no loop (yes a more complex loop with conditions switching the content of some locals for options is conceivable but contrived). Am I missing something about what's feasible with these two commands? I know there are many other commands (although I also think outreg2 (ssc des outreg2) wouldn't do what I want), but I'd like to understand what's feasible in this case. Thanks
    Last edited by Matteo Pinna Pintor; 04 Jul 2022, 01:37.
    I'm using StataNow/MP 18.5

  • #2
    Show your loop, enclosing a data example using dataex (or a Stata dataset).

    Comment


    • #3
      Here it is - hopefully simplified in a way that does not omit anything relevant for my case that I could not anticipate. Of course, now somehow it works better - no broken table between pages, although still sometimes two tables per page. No idea of what changed, a few hours ago I was getting broken tables between pages. The question remains relevant though - I'm especially interested in understanding if it can be made with tex3pt, as that command as the very appealing compile option. In esttab I was trying to use prehead() or postfoot() to include a \pagebreak but it conflicts with page and the output then omits either the beginning or the end of the document - and again this is solvable in a loop only in a contrived way.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(cdr_diff lncdr_diff) byte province float p_avg int year byte(curfew_any curfew_short curfew_long) int district
               .           . 17  9162.909 2009 0 0 0   4
        .2697668   .03837049 17  9162.909 2010 0 0 0   4
       -.3509531  -.05021238 17  9162.909 2011 0 0 0   4
        .4097657   .05838573 17  9162.909 2012 0 0 0   4
        .7155786   .09443724 17  9162.909 2013 0 0 0   4
       1.3798966    .1602249 17  9162.909 2014 0 0 0   4
      -1.2046642  -.13839722 17  9162.909 2015 0 0 0   4
        .6466398   .07666016 17  9162.909 2016 0 0 0   4
      -1.4641995  -.18283784 17  9162.909 2017 0 0 0   4
      -.21303606 -.029623866 17  9162.909 2018 0 0 0   4
      -.18476152  -.02642262 17  9162.909 2019 0 0 0   4
               .           . 18  31194.82 2009 0 0 0   7
        .3897531   .09675598 18  31194.82 2010 0 0 0   7
      -.50922346  -.12839174 18  31194.82 2011 0 0 0   7
      -.20655227  -.05717325 18  31194.82 2012 0 0 0   7
        .9850051   .24732256 18  31194.82 2013 0 0 0   7
       -.4244218  -.09916997 18  31194.82 2014 0 0 0   7
      -.51312184  -.13472319 18  31194.82 2015 0 0 0   7
       -.1075046  -.03068149 18  31194.82 2016 0 0 0   7
       -.3074191  -.09331822 18  31194.82 2017 0 0 0   7
       .31368685   .09513307 18  31194.82 2018 0 0 0   7
        .6746066   .17828047 18  31194.82 2019 0 0 0   7
               .           . 18 38150.453 2009 0 0 0   9
       -.4211578  -.10326934 18 38150.453 2010 0 0 0   9
       -.1804495  -.04773355 18 38150.453 2011 0 0 0   9
       -.3983765  -.11421788 18 38150.453 2012 0 0 0   9
        .3249807    .0941316 18 38150.453 2013 0 0 0   9
       -.4695771  -.13904238 18 38150.453 2014 0 0 0   9
        .3993299   .11943245 18 38150.453 2015 0 0 0   9
      .026871443  .007546782 18 38150.453 2016 0 0 0   9
        .4390333   .11585975 18 38150.453 2017 0 0 0   9
      -.28816342  -.07451403 18 38150.453 2018 0 0 0   9
      -.26048374  -.07249498 18 38150.453 2019 0 0 0   9
               .           . 26  6968.273 2009 0 0 0  33
        .6098323   .10813189 26  6968.273 2010 0 0 0  33
      .036310196  .006083846 26  6968.273 2011 0 0 0  33
      -1.4782338  -.28359807 26  6968.273 2012 0 0 0  33
         .384171   .08177912 26  6968.273 2013 0 0 0  33
       .19114685    .0383265 26  6968.273 2014 0 0 0  33
       2.2739348   .36971045 26  6968.273 2015 0 0 0  33
         .359086   .04765213 26  6968.273 2016 0 0 0  33
        -.817771  -.11202312 26  6968.273 2017 0 0 0  33
      -1.1113749  -.17566097 26  6968.273 2018 0 0 0  33
       1.0407681   .16537356 26  6968.273 2019 0 0 0  33
               .           . 52 152562.81 2009 0 0 0  73
      -.04774618  -.01288557 52 152562.81 2010 0 0 0  73
       -.4766953  -.13866532 52 152562.81 2011 0 0 0  73
      -.05956578   -.0187608 52 152562.81 2012 0 0 0  73
       -.8017821   -.2942527 52 152562.81 2013 0 0 0  73
        .8608165    .3128477 52 152562.81 2014 0 0 0  73
      -.12125611  -.03857553 52 152562.81 2015 0 0 0  73
        .3922298   .11975348 52 152562.81 2016 1 1 0  73
       -.7410574   -.2398232 52 152562.81 2017 1 1 0  73
       .16732073   .05939436 52 152562.81 2018 0 0 0  73
       -.0389111 -.013501048 52 152562.81 2019 0 0 0  73
               .           . 26 15398.818 2009 0 0 0  74
        .2310648   .05383849 26 15398.818 2010 0 0 0  74
       -.4460571  -.10667682 26 15398.818 2011 0 0 0  74
       .09904647  .024689794 26 15398.818 2012 0 0 0  74
       -.2375238  -.06026363 26 15398.818 2013 0 0 0  74
        1.206859   .27430332 26 15398.818 2014 0 0 0  74
       -1.394588   -.3246436 26 15398.818 2015 1 1 0  74
        .9145842   .22436488 26 15398.818 2016 0 0 0  74
        .6654944   .13648689 26 15398.818 2017 0 0 0  74
      -2.1624038  -.53538406 26 15398.818 2018 0 0 0  74
       2.0761654    .5187131 26 15398.818 2019 0 0 0  74
               .           . 26      2740 2009 0 0 0  98
      -1.7288704  -.10895371 26      2740 2010 0 0 0  98
      -1.4526272  -.10172033 26      2740 2011 0 0 0  98
      -2.1737137  -.17462206 26      2740 2012 0 0 0  98
        1.833722    .1492417 26      2740 2013 0 0 0  98
       -.4561062 -.035092592 26      2740 2014 0 0 0  98
       11.003098    .6214383 26      2740 2015 0 0 0  98
      -2.3011913  -.10180688 26      2740 2016 0 0 0  98
       -8.070738     -.47139 26      2740 2017 0 0 0  98
       1.7280273   .12128043 26      2740 2018 0 0 0  98
        .8642244   .05554914 26      2740 2019 0 0 0  98
               .           . 26 15013.546 2009 0 0 0 115
       -.9915891  -.13066733 26 15013.546 2010 0 0 0 115
        .9018722    .1195227 26 15013.546 2011 0 0 0 115
       -.5055208 -.065228224 26 15013.546 2012 0 0 0 115
       -.8183575   -.1155392 26 15013.546 2013 0 0 0 115
       2.0284367   .26511705 26 15013.546 2014 0 0 0 115
        .3801298   .04271698 26 15013.546 2015 0 0 0 115
        1.066103   .11089754 26 15013.546 2016 0 0 0 115
      -2.0222626   -.2220366 26 15013.546 2017 0 0 0 115
        -2.91581   -.4438988 26 15013.546 2018 0 0 0 115
        3.427503     .504907 26 15013.546 2019 0 0 0 115
               .           . 63     27044 2009 0 0 0 119
       -.2119119  -.05197263 63     27044 2010 0 0 0 119
      -.46293545  -.12390912 63     27044 2011 0 0 0 119
       -.2551334   -.0754782 63     27044 2012 0 0 0 119
        .1618936   .04855025 63     27044 2013 0 0 0 119
        .4267559   .11771429 63     27044 2014 0 0 0 119
        .3276641    .0818237 63     27044 2015 0 0 0 119
      -.20656157  -.05079675 63     27044 2016 0 0 0 119
       -.3663399  -.09696949 63     27044 2017 1 1 0 119
        .3396299   .09020853 63     27044 2018 1 1 0 119
        .2961235   .07251561 63     27044 2019 0 0 0 119
               .           . 23  366739.9 2009 0 0 0 126
      end
      format %ty year
      xtset district year
      foreach z in cdr_diff lncdr_diff {
      foreach x in 17 18 26 52 63 {
      tempvar anylongcurfew_`x'_`z'
      egen `anylongcurfew_`x'_`z'' = max(curfew_long) if province==`x'
      ereplace `anylongcurfew_`x'_`z'' = min(`anylongcurfew_`x'_`z'')
      foreach w in [aw=p_avg] " " {
      if "`w'"=="[aw=p_avg]" local weighted "YES"
      else local weighted "NO"
      local t : label (province) `x'
      set more off
      
      if cond(`anylongcurfew_`x'_`z''==1,1,0) {
      qui eststo: xtreg `z' c.year curfew_any if province==`x' `w', fe vce(cl district)
      qui eststo: xtreg `z' c.year curfew_short curfew_long if province==`x' `w', fe vce(cl district)
      qui eststo: xtreg `z' c.year c.year#c.year curfew_any if province==`x' `w', fe vce(cl district)
      qui eststo: xtreg `z' c.year c.year#c.year curfew_short curfew_long if province==`x' `w', fe vce(cl district)
      esttab using "$data\regs/trial`z'", se star(* 0.10 ** 0.05 *** 0.01) nonum coeflabels(c.year year c.year#c.year "year squared" curfew_any "any curfew" curfew_short "short curfew" curfew_long "long curfew") booktabs page append title("Province:`t'") nonotes addn("Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1" "Weighted for avg district population:`weighted'" "any curfew: at least on curfew imposed in district/year" "short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year" "long curfew: at least one curfew lasting longer than 7 days imposed in district/year")
      eststo clear
      }
      else {
      qui eststo: xtreg `z' c.year curfew_short if province==`x' `w', fe vce(cl district)    
      qui eststo: xtreg `z' c.year c.year#c.year curfew_short if province==`x' `w', fe vce(cl district)
      esttab using "$data\regs/trial`z'", se star(* 0.10 ** 0.05 *** 0.01) nonum coeflabels(c.year year c.year#c.year "year squared" curfew_short "short curfew") booktabs page append title("Province:`t'") nonotes addn("Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1" "Weighted for avg district population:`weighted'" "any curfew: at least on curfew imposed in district/year" "short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year" "long curfew: at least one curfew lasting longer than 7 days imposed in district/year")
      eststo clear
      }
      set more on
      }
      }
      }
      Last edited by Matteo Pinna Pintor; 04 Jul 2022, 08:24. Reason: typo correction
      I'm using StataNow/MP 18.5

      Comment


      • #4
        Thanks for the example. Try:

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float(cdr_diff lncdr_diff) byte province float p_avg int year byte(curfew_any curfew_short curfew_long) int district
                 .           . 17  9162.909 2009 0 0 0   4
          .2697668   .03837049 17  9162.909 2010 0 0 0   4
         -.3509531  -.05021238 17  9162.909 2011 0 0 0   4
          .4097657   .05838573 17  9162.909 2012 0 0 0   4
          .7155786   .09443724 17  9162.909 2013 0 0 0   4
         1.3798966    .1602249 17  9162.909 2014 0 0 0   4
        -1.2046642  -.13839722 17  9162.909 2015 0 0 0   4
          .6466398   .07666016 17  9162.909 2016 0 0 0   4
        -1.4641995  -.18283784 17  9162.909 2017 0 0 0   4
        -.21303606 -.029623866 17  9162.909 2018 0 0 0   4
        -.18476152  -.02642262 17  9162.909 2019 0 0 0   4
                 .           . 18  31194.82 2009 0 0 0   7
          .3897531   .09675598 18  31194.82 2010 0 0 0   7
        -.50922346  -.12839174 18  31194.82 2011 0 0 0   7
        -.20655227  -.05717325 18  31194.82 2012 0 0 0   7
          .9850051   .24732256 18  31194.82 2013 0 0 0   7
         -.4244218  -.09916997 18  31194.82 2014 0 0 0   7
        -.51312184  -.13472319 18  31194.82 2015 0 0 0   7
         -.1075046  -.03068149 18  31194.82 2016 0 0 0   7
         -.3074191  -.09331822 18  31194.82 2017 0 0 0   7
         .31368685   .09513307 18  31194.82 2018 0 0 0   7
          .6746066   .17828047 18  31194.82 2019 0 0 0   7
                 .           . 18 38150.453 2009 0 0 0   9
         -.4211578  -.10326934 18 38150.453 2010 0 0 0   9
         -.1804495  -.04773355 18 38150.453 2011 0 0 0   9
         -.3983765  -.11421788 18 38150.453 2012 0 0 0   9
          .3249807    .0941316 18 38150.453 2013 0 0 0   9
         -.4695771  -.13904238 18 38150.453 2014 0 0 0   9
          .3993299   .11943245 18 38150.453 2015 0 0 0   9
        .026871443  .007546782 18 38150.453 2016 0 0 0   9
          .4390333   .11585975 18 38150.453 2017 0 0 0   9
        -.28816342  -.07451403 18 38150.453 2018 0 0 0   9
        -.26048374  -.07249498 18 38150.453 2019 0 0 0   9
                 .           . 26  6968.273 2009 0 0 0  33
          .6098323   .10813189 26  6968.273 2010 0 0 0  33
        .036310196  .006083846 26  6968.273 2011 0 0 0  33
        -1.4782338  -.28359807 26  6968.273 2012 0 0 0  33
           .384171   .08177912 26  6968.273 2013 0 0 0  33
         .19114685    .0383265 26  6968.273 2014 0 0 0  33
         2.2739348   .36971045 26  6968.273 2015 0 0 0  33
           .359086   .04765213 26  6968.273 2016 0 0 0  33
          -.817771  -.11202312 26  6968.273 2017 0 0 0  33
        -1.1113749  -.17566097 26  6968.273 2018 0 0 0  33
         1.0407681   .16537356 26  6968.273 2019 0 0 0  33
                 .           . 52 152562.81 2009 0 0 0  73
        -.04774618  -.01288557 52 152562.81 2010 0 0 0  73
         -.4766953  -.13866532 52 152562.81 2011 0 0 0  73
        -.05956578   -.0187608 52 152562.81 2012 0 0 0  73
         -.8017821   -.2942527 52 152562.81 2013 0 0 0  73
          .8608165    .3128477 52 152562.81 2014 0 0 0  73
        -.12125611  -.03857553 52 152562.81 2015 0 0 0  73
          .3922298   .11975348 52 152562.81 2016 1 1 0  73
         -.7410574   -.2398232 52 152562.81 2017 1 1 0  73
         .16732073   .05939436 52 152562.81 2018 0 0 0  73
         -.0389111 -.013501048 52 152562.81 2019 0 0 0  73
                 .           . 26 15398.818 2009 0 0 0  74
          .2310648   .05383849 26 15398.818 2010 0 0 0  74
         -.4460571  -.10667682 26 15398.818 2011 0 0 0  74
         .09904647  .024689794 26 15398.818 2012 0 0 0  74
         -.2375238  -.06026363 26 15398.818 2013 0 0 0  74
          1.206859   .27430332 26 15398.818 2014 0 0 0  74
         -1.394588   -.3246436 26 15398.818 2015 1 1 0  74
          .9145842   .22436488 26 15398.818 2016 0 0 0  74
          .6654944   .13648689 26 15398.818 2017 0 0 0  74
        -2.1624038  -.53538406 26 15398.818 2018 0 0 0  74
         2.0761654    .5187131 26 15398.818 2019 0 0 0  74
                 .           . 26      2740 2009 0 0 0  98
        -1.7288704  -.10895371 26      2740 2010 0 0 0  98
        -1.4526272  -.10172033 26      2740 2011 0 0 0  98
        -2.1737137  -.17462206 26      2740 2012 0 0 0  98
          1.833722    .1492417 26      2740 2013 0 0 0  98
         -.4561062 -.035092592 26      2740 2014 0 0 0  98
         11.003098    .6214383 26      2740 2015 0 0 0  98
        -2.3011913  -.10180688 26      2740 2016 0 0 0  98
         -8.070738     -.47139 26      2740 2017 0 0 0  98
         1.7280273   .12128043 26      2740 2018 0 0 0  98
          .8642244   .05554914 26      2740 2019 0 0 0  98
                 .           . 26 15013.546 2009 0 0 0 115
         -.9915891  -.13066733 26 15013.546 2010 0 0 0 115
          .9018722    .1195227 26 15013.546 2011 0 0 0 115
         -.5055208 -.065228224 26 15013.546 2012 0 0 0 115
         -.8183575   -.1155392 26 15013.546 2013 0 0 0 115
         2.0284367   .26511705 26 15013.546 2014 0 0 0 115
          .3801298   .04271698 26 15013.546 2015 0 0 0 115
          1.066103   .11089754 26 15013.546 2016 0 0 0 115
        -2.0222626   -.2220366 26 15013.546 2017 0 0 0 115
          -2.91581   -.4438988 26 15013.546 2018 0 0 0 115
          3.427503     .504907 26 15013.546 2019 0 0 0 115
                 .           . 63     27044 2009 0 0 0 119
         -.2119119  -.05197263 63     27044 2010 0 0 0 119
        -.46293545  -.12390912 63     27044 2011 0 0 0 119
         -.2551334   -.0754782 63     27044 2012 0 0 0 119
          .1618936   .04855025 63     27044 2013 0 0 0 119
          .4267559   .11771429 63     27044 2014 0 0 0 119
          .3276641    .0818237 63     27044 2015 0 0 0 119
        -.20656157  -.05079675 63     27044 2016 0 0 0 119
         -.3663399  -.09696949 63     27044 2017 1 1 0 119
          .3396299   .09020853 63     27044 2018 1 1 0 119
          .2961235   .07251561 63     27044 2019 0 0 0 119
                 .           . 23  366739.9 2009 0 0 0 126
        end
        format %ty year
        xtset district year
        foreach z in cdr_diff lncdr_diff {
        foreach x in 17 18 26 52 63 {
        tempvar anylongcurfew_`x'_`z'
        egen `anylongcurfew_`x'_`z'' = max(curfew_long) if province==`x'
        ereplace `anylongcurfew_`x'_`z'' = min(`anylongcurfew_`x'_`z'')
        foreach w in [aw=p_avg] " " {
        if "`w'"=="[aw=p_avg]" local weighted "YES"
        else local weighted "NO"
        local t : label (province) `x'
        set more off
        
        if cond(`anylongcurfew_`x'_`z''==1,1,0) {
        qui eststo: xtreg `z' c.year curfew_any if province==`x' `w', fe vce(cl district)
        qui eststo: xtreg `z' c.year curfew_short curfew_long if province==`x' `w', fe vce(cl district)
        qui eststo: xtreg `z' c.year c.year#c.year curfew_any if province==`x' `w', fe vce(cl district)
        qui eststo: xtreg `z' c.year c.year#c.year curfew_short curfew_long if province==`x' `w', fe vce(cl district)
        esttab using "$data\regs/trial`z'_holding.tex", se star(* 0.10 ** 0.05 *** 0.01) nonum coeflabels(c.year year c.year#c.year "year squared" curfew_any "any curfew" curfew_short "short curfew" curfew_long "long curfew") booktabs page append title("Province:`t'") nonotes addn("Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1" "Weighted for avg district population:`weighted'" "any curfew: at least on curfew imposed in district/year" "short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year" "long curfew: at least one curfew lasting longer than 7 days imposed in district/year")
        filefilter "$data\regs/trial`z'_holding.tex" "$data\regs/trial`z'.tex", replace from("\BSend{table}") to("\BSend{table}\W\BSpagebreak")
        eststo clear
        }
        else {
        qui eststo: xtreg `z' c.year curfew_short if province==`x' `w', fe vce(cl district)    
        qui eststo: xtreg `z' c.year c.year#c.year curfew_short if province==`x' `w', fe vce(cl district)
        esttab using "$data\regs/trial`z'_holding.tex", se star(* 0.10 ** 0.05 *** 0.01) nonum coeflabels(c.year year c.year#c.year "year squared" curfew_short "short curfew") booktabs page append title("Province:`t'") nonotes addn("Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1" "Weighted for avg district population:`weighted'" "any curfew: at least on curfew imposed in district/year" "short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year" "long curfew: at least one curfew lasting longer than 7 days imposed in district/year")
        filefilter "$data\regs/trial`z'_holding.tex" "$data\regs/trial`z'.tex", replace from("\BSend{table}") to("\BSend{table}\W\BSpagebreak")
        eststo clear
        }
        set more on
        }
        }
        }
        where you are interested in the files named "$data\regs/trial`z'.tex" and not those with the suffix "_holding.tex".

        Res.:

        Code:
        \begin{table}[htbp]\centering
        \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
        \caption{Province:17}
        \begin{tabular}{l*{8}{c}}
        \toprule
                    &\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}\\
        \midrule
        year        &     -0.0926         &       66.31         &     -0.0926         &       66.31         &     -0.0926         &       66.31         &     -0.0926         &       66.31         \\
                    &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         \\
        \addlinespace
        short curfew&           0         &           0         &           0         &           0         &           0         &           0         &           0         &           0         \\
                    &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         \\
        \addlinespace
        year squared&                     &     -0.0165         &                     &     -0.0165         &                     &     -0.0165         &                     &     -0.0165         \\
                    &                     &         (.)         &                     &         (.)         &                     &         (.)         &                     &         (.)         \\
        \addlinespace
        \_cons      &       186.6         &    -66698.3         &       186.6         &    -66698.3         &       186.6         &    -66698.3         &       186.6         &    -66698.3         \\
                    &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         &         (.)         \\
        \midrule
        \(N\)       &          10         &          10         &          10         &          10         &          10         &          10         &          10         &          10         \\
        \bottomrule
        \multicolumn{9}{l}{\footnotesize Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1}\\
        \multicolumn{9}{l}{\footnotesize Weighted for avg district population:YES}\\
        \multicolumn{9}{l}{\footnotesize any curfew: at least on curfew imposed in district/year}\\
        \multicolumn{9}{l}{\footnotesize short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year}\\
        \multicolumn{9}{l}{\footnotesize long curfew: at least one curfew lasting longer than 7 days imposed in district/year}\\
        \end{tabular}
        \end{table}
        \pagebreak
        
        \begin{table}[htbp]\centering
        \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
        \caption{Province:17}
        \begin{tabular}{l*{2}{c}}
        \toprule
                    &\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}\\
        \midrule
        year        &     -0.0926         &       66.31         \\
                    &         (.)         &         (.)         \\
        \addlinespace
        short curfew&           0         &           0         \\
                    &         (.)         &         (.)         \\
        \addlinespace
        year squared&                     &     -0.0165         \\
                    &                     &         (.)         \\
        \addlinespace
        \_cons      &       186.6         &    -66698.3         \\
                    &         (.)         &         (.)         \\
        \midrule
        \(N\)       &          10         &          10         \\
        \bottomrule
        \multicolumn{3}{l}{\footnotesize Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1}\\
        \multicolumn{3}{l}{\footnotesize Weighted for avg district population:NO}\\
        \multicolumn{3}{l}{\footnotesize any curfew: at least on curfew imposed in district/year}\\
        \multicolumn{3}{l}{\footnotesize short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year}\\
        \multicolumn{3}{l}{\footnotesize long curfew: at least one curfew lasting longer than 7 days imposed in district/year}\\
        \end{tabular}
        \end{table}
        \pagebreak
        
        \begin{table}[htbp]\centering
        \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
        \caption{Province:17}
        \begin{tabular}{l*{2}{c}}
        \toprule
                    &\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}\\
        \midrule
        year        &     -0.0926         &       66.31         \\
                    &         (.)         &         (.)         \\
        \addlinespace
        short curfew&           0         &           0         \\
                    &         (.)         &         (.)         \\
        \addlinespace
        year squared&                     &     -0.0165         \\
                    &                     &         (.)         \\
        \addlinespace
        \_cons      &       186.6         &    -66698.3         \\
                    &         (.)         &         (.)         \\
        \midrule
        \(N\)       &          10         &          10         \\
        \bottomrule
        \multicolumn{3}{l}{\footnotesize Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1}\\
        \multicolumn{3}{l}{\footnotesize Weighted for avg district population:YES}\\
        \multicolumn{3}{l}{\footnotesize any curfew: at least on curfew imposed in district/year}\\
        \multicolumn{3}{l}{\footnotesize short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year}\\
        \multicolumn{3}{l}{\footnotesize long curfew: at least one curfew lasting longer than 7 days imposed in district/year}\\
        \end{tabular}
        \end{table}
        \pagebreak
        
        \begin{table}[htbp]\centering
        \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
        \caption{Province:17}
        \begin{tabular}{l*{2}{c}}
        \toprule
                    &\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}\\
        \midrule
        year        &     -0.0926         &       66.31         \\
                    &         (.)         &         (.)         \\
        \addlinespace
        short curfew&           0         &           0         \\
                    &         (.)         &         (.)         \\
        \addlinespace
        year squared&                     &     -0.0165         \\
                    &                     &         (.)         \\
        \addlinespace
        \_cons      &       186.6         &    -66698.3         \\
                    &         (.)         &         (.)         \\
        \midrule
        \(N\)       &          10         &          10         \\
        \bottomrule
        \multicolumn{3}{l}{\footnotesize Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1}\\
        \multicolumn{3}{l}{\footnotesize Weighted for avg district population:NO}\\
        \multicolumn{3}{l}{\footnotesize any curfew: at least on curfew imposed in district/year}\\
        \multicolumn{3}{l}{\footnotesize short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year}\\
        \multicolumn{3}{l}{\footnotesize long curfew: at least one curfew lasting longer than 7 days imposed in district/year}\\
        \end{tabular}
        \end{table}
        \pagebreak
        
        \begin{table}[htbp]\centering
        \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
        \caption{Province:18}
        \begin{tabular}{l*{2}{c}}
        \toprule
                    &\multicolumn{1}{c}{cdr\_diff}&\multicolumn{1}{c}{cdr\_diff}\\
        \midrule
        year        &      0.0283\sym{**} &      -3.279         \\
                    &   (0.00123)         &     (125.2)         \\
        \addlinespace
        short curfew&           0         &           0         \\
                    &         (.)         &         (.)         \\
        \addlinespace
        year squared&                     &    0.000821         \\
                    &                     &    (0.0311)         \\
        \addlinespace
        \_cons      &      -57.09\sym{**} &      3274.2         \\
                    &     (2.485)         &  (126075.4)         \\
        \midrule
        \(N\)       &          20         &          20         \\
        \bottomrule
        \multicolumn{3}{l}{\footnotesize Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1}\\
        \multicolumn{3}{l}{\footnotesize Weighted for avg district population:YES}\\
        \multicolumn{3}{l}{\footnotesize any curfew: at least on curfew imposed in district/year}\\
        \multicolumn{3}{l}{\footnotesize short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year}\\
        \multicolumn{3}{l}{\footnotesize long curfew: at least one curfew lasting longer than 7 days imposed in district/year}\\
        \end{tabular}
        \end{table}
        \pagebreak
        Last edited by Andrew Musau; 04 Jul 2022, 18:30.

        Comment


        • #5
          Oh. Didn't know filefilter. Very fitting. Let me also add that, given that, it is easy to modify to automatize also the pdf generation using tex3pt. Thanks Andrew.

          Code:
          foreach z in cdr_diff lncdr_diff {
          foreach x in 17 18 26 52 63 {
          tempvar anylongcurfew_`x'_`z' egen `anylongcurfew_`x'_`z'' = max(curfew_long) if province==`x' ereplace `anylongcurfew_`x'_`z'' = min(`anylongcurfew_`x'_`z'')
          foreach w in [aw=p_avg] " " {
          if "`w'"=="[aw=p_avg]" local weighted "YES"
          else local weighted "NO"
          local t : label (province) `x'
          set more off
          if cond(`anylongcurfew_`x'_`z''==1,1,0) {
          qui eststo: xtreg `z' c.year curfew_any if province==`x' `w', fe vce(cl district)
          qui eststo: xtreg `z' c.year curfew_short curfew_long if province==`x' `w', fe vce(cl district)
          qui eststo: xtreg `z' c.year c.year#c.year curfew_any if province==`x' `w', fe vce(cl district)
          qui eststo: xtreg `z' c.year c.year#c.year curfew_short curfew_long if province==`x' `w', fe vce(cl district)
          esttab using "$data\regs/trial`z'_holding.tex", se star(* 0.10 ** 0.05 *** 0.01) nonum coeflabels(c.year year c.year#c.year "year squared" curfew_any "any curfew" curfew_short "short curfew" curfew_long "long curfew") booktabs page append title("Province:`t'") nonotes addn("Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1" "Weighted for avg district population:`weighted'" "any curfew: at least on curfew imposed in district/year" "short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year" "long curfew: at least one curfew lasting longer than 7 days imposed in district/year")
          filefilter "$data\regs/trial`z'_holding.tex" "$data\regs/trial`z'.tex", replace from("\BSend{table}") to("\BSend{table}\W\BSpagebreak")
          eststo clear
          }
          else {
          qui eststo: xtreg `z' c.year curfew_short if province==`x' `w', fe vce(cl district)
          qui eststo: xtreg `z' c.year c.year#c.year curfew_short if province==`x' `w', fe vce(cl district)
          esttab using "$data\regs/trial`z'_holding.tex", se star(* 0.10 ** 0.05 *** 0.01) nonum coeflabels(c.year year c.year#c.year "year squared" curfew_short "short curfew") booktabs page append title("Province:`t'") nonotes addn("Standard errors below coefficient estimates, clustered at the district level. *** p$<$.01, ** p$<$.05, * p$<$.1" "Weighted for avg district population:`weighted'" "any curfew: at least on curfew imposed in district/year" "short curfew: at least one curfew lasting up to 7 days, and none lasting longer, imposed in district/year" "long curfew: at least one curfew lasting longer than 7 days imposed in district/year")
          filefilter "$data\regs/trial`z'_holding.tex" "$data\regs/trial`z'.tex", replace from("\BSend{table}") to("\BSend{table}\W\BSpagebreak")
          eststo clear
          }
          set more on
          }
          }
          tex3pt using "$data\regs/trial`z'.tex", enddoc compile
          }
          Last edited by Matteo Pinna Pintor; 05 Jul 2022, 02:50.
          I'm using StataNow/MP 18.5

          Comment

          Working...
          X