Announcement

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

  • Exporting tables with regression coefficients and boottest pvalues

    I am performing regressions that I would like to export in LaTeX-format tables. Due to a low sample size in my dataset, I adjust the p-values of my regression coefficients using a boottest. Here's my code:

    ```
    eststo reg1 : reg var treated control1 control2 control3, cluster(subgroup) robust
    matrix beta=e(b)
    coeff=beta[1,1]
    boottest treated, boottype(wild) cluster(subgroup) robust nograph seed(1234) reps(10000)
    pval = r(p)
    ```
    I would like to export the treated coefficient obtained in the regression alongside the p-value found in the boottest and the significance stars. I would normally just use esttab but esttab uses the s.e. from the regression, which I do not want. Is there a way to do this or do I jave to construct a custom table from scratch ?

  • #2
    boottest is from SSC (FAQ Advice #12).

    #9 may help: https://www.statalist.org/forums/for...t-few-clusters

    Comment


    • #3
      Dear Andrew, thanks for the response. I went over and looked at the post you linked, it is indeed what I want to do but the code in #9 does not work for me. For some reason, the do-file does not run the whole way through

      Code :
      Code:
      eststo m1: reg var treated control1 control2 control3, cluster(subgroup) robust
      local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country|robust|\,|cluster\(|c ountry|\)", "")
      
      local pvals
      local tstat
      set seed 02202022
      foreach var of local vars{
      boottest `var', boottype(wild) cluster(subgroup) robust nograph seed(1234) reps(10000)
      local pvals= "`pvals' `=r(p)'"
      local tstat= "`tstat' `=r(t)'"
      }
      
      DO FILE STOPS HERE
      
      di "`pvals'"
      di "`tstat'"
      foreach stat in pvals tstat{
      local `stat'= "("+ ustrregexra(trim("``stat''"), " ", ",") + ")"
      mat `stat'= ``stat''
      mat colnames `stat'= `vars'
      estadd matrix `stat': m1
      }
      
      eststo m2: reg var2 treated control1 control2 control3, cluster(subgroup) robust
      local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country|robust|\,|cluster\(|c ountry|\)", "")
      
      local pvals
      local tstat
      set seed 02202022
      foreach var of local vars{
      boottest `var', boottype(wild) cluster(subgroup) robust nograph seed(1234) reps(10000)
      local pvals= "`pvals' `=r(p)'"
      local tstat= "`tstat' `=r(t)'"
      }
      di "`pvals'"
      di "`tstat'"
      foreach stat in pvals tstat{
      local `stat'= "("+ ustrregexra(trim("``stat''"), " ", ",") + ")"
      mat `stat'= ``stat''
      mat colnames `stat'= `vars'
      estadd matrix `stat': m2
      }
      
      
      esttab m1 m2 using myfile.tex, replace cells(b(fmt(3) pvalue(pvals) star) tstat(par fmt(2))) drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) addnotes("Some description of the dependent variables and models HERE." "Wild cluster t-statistics in parentheses." "* p<0.10, ** p<0.05, *** p<0.01") varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
      I think the reason is because one of my controls is a variable that represents different stratas in my observations. The strata is the interaction between geographic region and socio-economic status. I get that error message :

      Code:
      Overriding estimator's cluster/robust settings with cluster(subgroup)
      note: constraint i.strata caused error r(111)
      r(111);
      
      end of do-file
      Do you know how I can fix this ?

      Comment


      • #4
        Ignore this.
        Last edited by Michael Wegmuller; 17 May 2022, 09:45. Reason: Double posted reply

        Comment


        • #5
          As I stated in the linked thread, you do not need to cluster when you are running the regression as boottest will do the clustering for you.

          Code:
          eststo m2: reg var2 treated control1 control2 control3
          local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country\)", "")

          Also, the option -robust- in regress computes White standard errors, and it does not make sense to specify both -robust- and -cluster(clustervar)-.

          I think the reason is because one of my controls is a variable that represents different stratas in my observations. The strata is the interaction between geographic region and socio-economic status. I get that error message :
          I cannot tell you what the issue is as you are showing pseudo code. The -foreach- loop in the linked thread is based on variable names and does not take into account interactions. You need to provide a reproducible example for anything concrete.
          Last edited by Andrew Musau; 18 May 2022, 06:30.

          Comment


          • #6
            You should do "set trace on" and figure out why your code is apparently doing something like "boottest i.strata".

            Comment


            • #7
              You wouldn't parse the command line if you are interested in the coefficients of a factor variable. My guess is that the OP is doing something like

              Code:
              webuse grunfeld, clear
              gen strata=runiformint(1,6)
              qui regress invest mvalue kstock i.strata i.company i.year
              local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.company", "")
              di "`vars'"
              Res.:

              Code:
              
              .
              . local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.company", "")
              
              .
              . di "`vars'"
               mvalue kstock i.strata
              boottest loops over the contents of the local "vars". But as I said, I need a reproducible example.

              Comment


              • #8
                Thank you for the replies. I will give a reproductible example with my data:

                Code:
                * Example generated by -dataex-. For more info, type help dataex
                clear
                input float(nb_amis_travaille2 treated nb_amis_travaille1) byte mise_en_situation_42 float(PCAmotiv2 PCApers2 PCAcoop2 IncrCoop2 IncrPers2 IncrMotiv2) byte class_id float strata
                 0 0  8 1  -2.577016 -1.5837188 -1.5748777 11 10 17 6 3
                 0 0  0 1   .6280397      .5804 -1.1302912 12 14 26 6 3
                16 0  1 1   -2.37504  1.3719666  -.9493558 13 11 18 6 3
                 0 0  0 1  1.6310042  1.3719666   .9158205 16 11 28 6 3
                 6 0  0 0  2.1372192  1.3719666  1.3461018 19 11 30 6 3
                 0 0  1 .  -.8753191  -2.466335 -1.2159078 12  6 21 6 3
                 6 0  0 1  1.8841118  1.3719666 -.17369947 14 11 29 6 3
                 3 0  0 1  .19847615   .9898093  -.9647563 12 10 24 6 3
                 2 0  2 1 -.41989335  1.3719666  -.7702186 13 11 24 6 3
                 0 0  8 0  -2.921329  -.9897316  -.9579551 12 11 15 6 3
                 0 0  0 0  -4.090744  -2.611889  -.9955647 13  9 14 6 3
                 0 0  4 1  -.2969517  1.3719666  -.8791396 12 11 23 6 3
                 0 0  0 0   -.905417  1.3719666   .4769324 15 11 21 6 3
                 5 0  0 1   .9128304   .9898093 -1.1821985 12 10 27 6 3
                 6 0  1 1 -1.6718596   .3165444   -.909948 13 15 20 6 3
                 6 0  0 1  2.1372192 -.15666245  1.1429648 17  7 30 6 3
                 0 0 11 0   .4668632  -.4099948   -.049378 16  8 25 6 3
                 0 0  0 1  .46322775  -.4620205  1.1429648 17  9 25 6 3
                 4 0  6 0  2.1372192   .3165444 -.27362132 16 15 30 8 2
                 3 0  3 0  -.6757795   1.108111  -1.654796 11 12 22 8 2
                end
                label values treated treatment
                label def treatment 0 "Contrôle", modify
                Here's my code

                Code:
                global PCA PCAcoop2 PCAmotiv2 PCApers2
                global IncrIndex2 IncrCoop2 IncrMotiv2 IncrPers2
                
                global PCA PCAcoop2 PCAmotiv2 PCApers2
                global IncrIndex IncrCoop2 IncrMotiv2 IncrPers2
                *egen strata = group(academie class_status)
                
                
                eststo m1: reg nb_amis_travaille2 treated nb_amis_travaille1 i.strata $PCA $IncrIndex mise_en_situation_42
                local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country|robust|\,|cluster\(|c ountry|\)", "")
                
                local pvals
                local tstat
                set seed 02202022
                foreach var of local vars{
                    boottest `var', boottype(wild) cluster(class_id) robust nograph seed(1234) reps(10000)
                    local pvals= "`pvals' `=r(p)'"
                    local tstat= "`tstat' `=r(t)'"
                }
                
                di "`pvals'"
                di "`tstat'"
                foreach stat in pvals tstat{
                    local `stat'= "("+ ustrregexra(trim("``stat''"), " ", ",") + ")"
                    mat `stat'= ``stat''
                    mat colnames `stat'= `vars'
                    estadd matrix `stat': m1
                }
                
                eststo m2: reg questionshebdo42 treated questionshebdo41 $PCA $IncrIndex mise_en_situation_42 i.strata
                
                local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country|robust|\,|cluster\(|c ountry|\)", "")
                
                local pvals
                local tstat
                set seed 02202022
                foreach var of local vars{
                    boottest `var', boottype(wild) cluster(subgroup) robust nograph seed(1234) reps(10000)
                    local pvals= "`pvals' `=r(p)'"
                    local tstat= "`tstat' `=r(t)'"
                }
                di "`pvals'"
                di "`tstat'"
                foreach stat in pvals tstat{
                    local `stat'= "("+ ustrregexra(trim("``stat''"), " ", ",") + ")"
                    mat `stat'= ``stat''
                    mat colnames `stat'= `vars'
                    estadd matrix `stat': m2
                }
                
                
                esttab m1 m2 using myfile.tex, replace cells(b(fmt(3) pvalue(pvals) star) tstat(par fmt(2))) drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) addnotes("Some description of the dependent variables and models HERE." "Wild cluster t-statistics in parentheses." "* p<0.10, ** p<0.05, *** p<0.01") varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                I still get the same error message:

                Code:
                 
                 Overriding estimator's cluster/robust settings with cluster(subgroup) note: constraint i.strata caused error r(111) r(111);  end of do-file
                Question for David as I saw his paper during my research on bootstrapping : would using the option vce(bootstrap) in the regression command give me the same result as the boottest postestimation command as done above ?
                Like this:
                Code:
                reg nb_amis_travaille2 treated nb_amis_travaille1 i.strata $PCA $IncrIndex mise_en_situation_42, vce(bootstrap)
                Thanks again for the help.

                Comment


                • #9
                  Change the line

                  local vars = ustrregexra("`e(cmdline)'", "regress `e(depvar)'|i.year|i.country|robust|\,|cluster\(|c ountry|\)", "")
                  to

                  Code:
                  local vars = ustrregexra("`:colnames e(b)'", "o\.\w+|\d+b\.\w+|\_cons", "")

                  Comment


                  • #10
                    HI Andrew, thanks a lot for the reply, it now works.

                    I can see the table with all the features I am looking for on the Stata console but LaTeX refuses to compile it. Here's the LaTeX code :

                    Code:
                    {
                    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
                    \begin{tabular}{l*{2}{c}}
                    \hline\hline
                                                  &\multicolumn{1}{c}{(1)}   &\multicolumn{1}{c}{(2)}   \\
                    \hline
                    treated                       &       0.132   &      -0.006   \\
                                                  &      (0.20)   &     (-0.23)   \\
                    nb\_amis\_travaille1            &       0.105   &               \\
                                                  &      (0.85)   &               \\
                    1.strata                      &       0.000   &       0.000   \\
                                                  &               &               \\
                    2.strata                      &      -0.104   &      -0.028   \\
                                                  &     (-0.13)   &     (-0.76)   \\
                    3.strata                      &       0.830   &       0.070   \\
                                                  &      (1.86)   &      (2.10)   \\
                    4.strata                      &      -0.014   &       0.065   \\
                                                  &     (-0.02)   &      (1.88)   \\
                    5.strata                      &      -0.001   &       0.049   \\
                                                  &     (-0.00)   &      (1.23)   \\
                    6.strata                      &       0.515   &      -0.079   \\
                                                  &      (1.13)   &     (-3.85)   \\
                    PCAcoop2                      &      -0.478   &      -3.853***\\
                                                  &     (-0.55)   &    (-63.66)   \\
                    PCAmotiv2                     &       1.484   &       0.051   \\
                                                  &      (1.28)   &      (0.76)   \\
                    PCApers2                      &      -0.072   &      -0.007   \\
                                                  &     (-0.27)   &     (-0.59)   \\
                    IncrCoop2                     &       0.350   &       1.834***\\
                                                  &      (0.94)   &     (71.07)   \\
                    IncrMotiv2                    &      -0.551   &      -0.017   \\
                                                  &     (-1.33)   &     (-0.65)   \\
                    IncrPers2                     &       0.132   &       0.004   \\
                                                  &      (1.78)   &      (0.59)   \\
                    mise\_en\_situation\_42          &       0.053   &      -0.016   \\
                                                  &      (0.09)   &     (-0.65)   \\
                    questionshebdo41              &               &       0.016*  \\
                                                  &               &      (1.81)   \\
                    \hline
                    Observations                  &         378   &         365   \\
                    Adjusted R-squared            &    -0.00865   &       0.967   \\
                    \hline\hline
                    \multicolumn{3}{l}{\footnotesize Some description of the dependent variables and models HERE.}\\
                    \multicolumn{3}{l}{\footnotesize Wild cluster t-statistics in parentheses.}\\
                    \multicolumn{3}{l}{\footnotesize * p<0.10, ** p<0.05, *** p<0.01}\\
                    \end{tabular}
                    }
                    I get the following error messages. The first error message appears twice, this is not my putting it here twice by accident :

                    Code:
                    Misplaced \cr. , myfile.tex 46
                    Misplaced \cr. , myfile.tex 46
                    Misplaced } , myfile.tex 45
                    Misplaced \endgroup , myfile.tex 45
                    Apparently most of these are automatically solved by LaTeX who replaces the missing characters so I don't understand why it refuses to compile

                    Comment


                    • #11
                      You can append to the code:


                      Code:
                      esttab m1 m2 using mytable.tex, replace cells(b(fmt(3) pvalue(pvals) star) ///
                      tstat(par fmt(2))) drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) ///
                      addnotes("Some description of the dependent variables and models HERE." ///
                      "Wild cluster t-statistics in parentheses." "* p<0.10, ** p<0.05, *** p<0.01") ///
                      varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                      
                      // backup table and open new file
                      copy mytable.tex tmp.tex
                      file open fh using mytable.tex, write replace
                      // write top lines
                      file write fh "\documentclass{article}" _n
                      file write fh "\usepackage{multirow}" _n
                      file write fh "\usepackage{amsmath}" _n
                      file write fh "\usepackage{booktabs}" _n
                      file write fh "\usepackage{ulem}" _n
                      file write fh "\usepackage[table]{xcolor}" _n
                      file write fh "\begin{document}" _n
                      file write fh "\begin{table}[ht]" _n
                      file write fh _n "\begin{footnotesize}" _n
                      file write fh "\centering" _n
                      // now insert the table
                      file open fh2 using tmp.tex, read
                      file read fh2 line
                      while r(eof)==0 {
                          file write fh `"`line'"' _n
                          file read fh2 line
                      }
                      file close fh2
                      // write bottom lines
                      file write fh _n "\end{footnotesize}" _n
                      file write fh _n "\end{table}" _n
                      file write fh _n "\end{document}" _n
                      // clean up
                      file close fh
                      erase tmp.tex
                      and then try compiling. Note that you run all these in a do file.

                      Comment


                      • #12
                        I tried but it does not work.

                        Do-file :

                        Code:
                        global PCA PCAcoop2 PCAmotiv2 PCApers2
                        global IncrIndex IncrCoop2 IncrMotiv2 IncrPers2
                        *egen strata = group(academie class_status)
                        
                        
                        eststo m1: reg nb_amis_travaille2 treated nb_amis_travaille1 i.strata $PCA $IncrIndex mise_en_situation_42
                        local vars = ustrregexra("`:colnames e(b)'", "o\.\w+|\d+b\.\w+|\_cons", "")
                        
                        local pvals
                        local tstat
                        set seed 02202022
                        foreach var of local vars{
                            boottest `var', boottype(wild) cluster(class_id) robust nograph seed(1234) reps(10000)
                            local pvals= "`pvals' `=r(p)'"
                            local tstat= "`tstat' `=r(t)'"
                        }
                        
                        di "`pvals'"
                        di "`tstat'"
                        foreach stat in pvals tstat{
                            local `stat'= "("+ ustrregexra(trim("``stat''"), " ", ",") + ")"
                            mat `stat'= ``stat''
                            mat colnames `stat'= `vars'
                            estadd matrix `stat': m1
                        }
                        
                        eststo m2: reg questionshebdo42 treated questionshebdo41 $PCA $IncrIndex mise_en_situation_42 i.strata
                        local vars = ustrregexra("`:colnames e(b)'", "o\.\w+|\d+b\.\w+|\_cons", "")
                        
                        local pvals
                        local tstat
                        set seed 02202022
                        foreach var of local vars{
                            boottest `var', boottype(wild) cluster(class_id) robust nograph seed(1234) reps(10000)
                            local pvals= "`pvals' `=r(p)'"
                            local tstat= "`tstat' `=r(t)'"
                        }
                        di "`pvals'"
                        di "`tstat'"
                        foreach stat in pvals tstat{
                            local `stat'= "("+ ustrregexra(trim("``stat''"), " ", ",") + ")"
                            mat `stat'= ``stat''
                            mat colnames `stat'= `vars'
                            estadd matrix `stat': m2
                        }
                        
                        esttab m1 m2 using mytable.tex, replace cells(b(fmt(3) pvalue(pvals) star) ///
                        tstat(par fmt(2))) drop(_cons) nomtitles collab(none) starlevels( * 0.10 ** 0.05 *** 0.010) ///
                        addnotes("Some description of the dependent variables and models HERE." ///
                        "Wild cluster t-statistics in parentheses." "* p<0.10, ** p<0.05, *** p<0.01") ///
                        varwidth(30) stats(N r2_a, labels(Observations "Adjusted R-squared") fmt(a3))
                        
                        // backup table and open new file
                        copy mytable.tex tmp.tex
                        file open fh using mytable.tex, write replace
                        // write top lines
                        file write fh "\documentclass{article}" _n
                        file write fh "\usepackage{multirow}" _n
                        file write fh "\usepackage{amsmath}" _n
                        file write fh "\usepackage{booktabs}" _n
                        file write fh "\usepackage{ulem}" _n
                        file write fh "\usepackage[table]{xcolor}" _n
                        file write fh "<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math MJXp-display" id="MJXp-Span-13"><span class="MJXp-merror" id="MJXp-Span-14"><span class="MJXp-mtext" id="MJXp-Span-15">\begin{document}"&nbsp;_n
                        file&nbsp;write&nbsp;fh&nbsp;"\begin{table}[ht]"&nbsp;_n
                        file&nbsp;write&nbsp;fh&nbsp;_n&nbsp;"\begin{footnotesize}"&nbsp;_n
                        file&nbsp;write&nbsp;fh&nbsp;"\centering"&nbsp;_n
                        //&nbsp;now&nbsp;insert&nbsp;the&nbsp;table
                        file&nbsp;open&nbsp;fh2&nbsp;using&nbsp;tmp.tex,&nbsp;read
                        file&nbsp;read&nbsp;fh2&nbsp;line
                        while&nbsp;r(eof)==0&nbsp;{
                        &nbsp;&nbsp;&nbsp;&nbsp;file&nbsp;write&nbsp;fh&nbsp;`"`line'"'&nbsp;_n
                        &nbsp;&nbsp;&nbsp;&nbsp;file&nbsp;read&nbsp;fh2&nbsp;line
                        }
                        file&nbsp;close&nbsp;fh2
                        //&nbsp;write&nbsp;bottom&nbsp;lines
                        file&nbsp;write&nbsp;fh&nbsp;_n&nbsp;"\end{footnotesize}"&nbsp;_n
                        file&nbsp;write&nbsp;fh&nbsp;_n&nbsp;"\end{table}"&nbsp;_n
                        file&nbsp;write&nbsp;fh&nbsp;_n&nbsp;"\end{document}</span></span></span></span><script type="math/tex; mode=display" id="MathJax-Element-2">\begin{document}" _n
                        file write fh "\begin{table}[ht]" _n
                        file write fh _n "\begin{footnotesize}" _n
                        file write fh "\centering" _n
                        // now insert the table
                        file open fh2 using tmp.tex, read
                        file read fh2 line
                        while r(eof)==0 {
                            file write fh `"`line'"' _n
                            file read fh2 line
                        }
                        file close fh2
                        // write bottom lines
                        file write fh _n "\end{footnotesize}" _n
                        file write fh _n "\end{table}" _n
                        file write fh _n "\end{document}</script>" _n
                        // clean up
                        file close fh
                        erase tmp.tex
                        Apparently the last append you wrote adds \begin{document} and other commands to the table while these belong to the main.tex. I tried removing them but it does not work either. I tried compiling the table in a blank LaTeX file but I obtained the same errors.

                        LaTeX code:

                        Code:
                        \input{Regression tables/mytable}
                        LaTeX error messages:

                        Code:
                        LaTeX error : can only be used in preamble, 1
                        LaTeX error : can only be used in preamble, 2
                        LaTeX error : can only be used in preamble, 3
                        LaTeX error : can only be used in preamble, 4
                        LaTeX error : can only be used in preamble, 5
                        LaTeX error : can only be used in preamble, 6
                        LaTeX error : can only be used in preamble, 7
                        
                        
                        missing \endgroup inserted, 56
                        missing } inserted, 56
                        missing } inserted, 57
                        misplaced \cr, 57
                        misplaced \cr, 57

                        Comment


                        • #13
                          What the code in #11 does is to allow you to compile the code directly. It will take the table generated by esttab and include the top lines and the bottom lines shown. If I take your table in #10 and compile in my editor, I get no such errors. If you do not have much experience with LaTeX, find a colleague who does and is willing to help.

                          Code:
                          \documentclass{article}
                          \usepackage{multirow}
                          \usepackage{amsmath}
                          \usepackage{booktabs}
                          \usepackage{ulem}
                          \usepackage[table]{xcolor}
                          \begin{document}
                          \begin{table}[ht]
                          \begin{footnotesize}
                          \centering
                          \begin{tabular}{l*{2}{c}}
                          \hline\hline
                                                        &\multicolumn{1}{c}{(1)}   &\multicolumn{1}{c}{(2)}   \\
                          \hline
                          treated                       &       0.132   &      -0.006   \\
                                                        &      (0.20)   &     (-0.23)   \\
                          nb\_amis\_travaille1            &       0.105   &               \\
                                                        &      (0.85)   &               \\
                          1.strata                      &       0.000   &       0.000   \\
                                                        &               &               \\
                          2.strata                      &      -0.104   &      -0.028   \\
                                                        &     (-0.13)   &     (-0.76)   \\
                          3.strata                      &       0.830   &       0.070   \\
                                                        &      (1.86)   &      (2.10)   \\
                          4.strata                      &      -0.014   &       0.065   \\
                                                        &     (-0.02)   &      (1.88)   \\
                          5.strata                      &      -0.001   &       0.049   \\
                                                        &     (-0.00)   &      (1.23)   \\
                          6.strata                      &       0.515   &      -0.079   \\
                                                        &      (1.13)   &     (-3.85)   \\
                          PCAcoop2                      &      -0.478   &      -3.853***\\
                                                        &     (-0.55)   &    (-63.66)   \\
                          PCAmotiv2                     &       1.484   &       0.051   \\
                                                        &      (1.28)   &      (0.76)   \\
                          PCApers2                      &      -0.072   &      -0.007   \\
                                                        &     (-0.27)   &     (-0.59)   \\
                          IncrCoop2                     &       0.350   &       1.834***\\
                                                        &      (0.94)   &     (71.07)   \\
                          IncrMotiv2                    &      -0.551   &      -0.017   \\
                                                        &     (-1.33)   &     (-0.65)   \\
                          IncrPers2                     &       0.132   &       0.004   \\
                                                        &      (1.78)   &      (0.59)   \\
                          mise\_en\_situation\_42          &       0.053   &      -0.016   \\
                                                        &      (0.09)   &     (-0.65)   \\
                          questionshebdo41              &               &       0.016*  \\
                                                        &               &      (1.81)   \\
                          \hline
                          Observations                  &         378   &         365   \\
                          Adjusted R-squared            &    -0.00865   &       0.967   \\
                          \hline\hline
                          \multicolumn{3}{l}{\footnotesize Some description of the dependent variables and models HERE.}\\
                          \multicolumn{3}{l}{\footnotesize Wild cluster t-statistics in parentheses.}\\
                          \multicolumn{3}{l}{\footnotesize * p$<$0.10, ** p$<$0.05, *** p$<$0.01}\\
                          \end{tabular}
                          \end{footnotesize}
                          \end{table}
                          \end{document}
                          Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	100.2 KB
ID:	1665582

                          Comment


                          • #14
                            Andrew Musau, I want to generate a table like the uploaded picture, and I am writing my code as follows. The latex codes are running but I cannot take my results from stata to latex. Would you please help me modify the code so that I can obtain results like the attached one.
                            "

                            * Load the final data file
                            use "$final_data\final children & parents 5 years avg.dta", clear

                            * Calculate distinct counts for father, mother, sons, and daughters
                            distinct xwaveid_biofather if hgage_c >= 18
                            local unique_father = r(ndistinct)

                            distinct xwaveid_biomother if hgage_c >= 18
                            local unique_mother = r(ndistinct)

                            summarize hgsex_c if hgsex_c == 1 & hgage_c >= 18
                            local unique_son = r(N)

                            summarize hgsex_c if hgsex_c == 2 & hgage_c >= 18
                            local unique_daughter = r(N)

                            // Clear previous estimates
                            eststo clear

                            foreach fm in ghpf ghrp ghbp ghgh ghvt ghsf ghre ghmh {
                            xtile father_rank_`fm' = `fm'_F, nq(100)
                            xtile mother_rank_`fm' = `fm'_M, nq(100)
                            clonevar son_`fm' = `fm'_c if hgsex_c == 1
                            xtile son_rank_`fm' = son_`fm', nq(100)
                            clonevar daughter_`fm' = `fm'_c if hgsex_c == 2
                            xtile daughter_rank_`fm' = daughter_`fm', nq(100)

                            label variable father_rank_`fm' "Father Rank `fm'"
                            label variable mother_rank_`fm' "Mother Rank `fm'"
                            label variable son_rank_`fm' "Son Rank `fm'"
                            label variable daughter_rank_`fm' "Daughter Rank `fm'"

                            * Run Rank-Rank Regressions and store estimates
                            eststo clear

                            foreach child in son daughter {
                            foreach parent in father mother {
                            eststo: regress `child'_rank_`fm' `parent'_rank_`fm', vce(cluster vhhrhid)
                            eststo: margins, at(`parent'_rank_`fm'=(25 50 75))
                            }
                            }

                            * Save the combined table for the rank-rank regressions
                            esttab using "$outdir/results_`fm'.tex", replace f ///
                            b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) booktabs ///
                            collabels(none) mtitles("Son-father" "Son-mother" "Daughter-father" "Daughter-mother") ///
                            title("Intergenerational Residualized Rank Regression in `fm' \label{reg1}")

                            }


                            * Clear previous estimates
                            eststo clear

                            * Define the program to calculate the IGC
                            program define calc_igc, rclass
                            args child parent
                            tempvar beta sigma_p sigma_c igc
                            regress `child' `parent', vce(cluster vhhrhid)
                            scalar `beta' = _b[`parent']
                            summarize `parent'
                            scalar `sigma_p' = r(sd)
                            summarize `child'
                            scalar `sigma_c' = r(sd)
                            scalar `igc' = `beta' * `sigma_p' / `sigma_c'
                            return scalar igc = `igc'
                            end

                            foreach fm in ghpf ghrp ghbp ghgh ghvt ghsf ghre ghmh {

                            foreach child in son daughter {
                            foreach parent in father mother {
                            bootstrap igc=r(igc), reps(100) seed(12345): calc_igc `child'_rank_`fm' `parent'_rank_`fm'

                            }
                            }
                            eststo: estadd scalar `child'`parent'_igc = r(igc)
                            eststo: estadd scalar `child'`parent'_se = r(se)

                            * Save the IGC results to a LaTeX table
                            esttab using "$outdir/results_`fm'.tex", append f b(3) se(3) label star(* 0.10 ** 0.05 *** 0.01) ///
                            addnotes("Data: HILDA 1 and 22 waves") postfoot(\bottomrule \end{tabular}) ///
                            booktabs collabels(none) nomtitles nolines nonum alignment(D{.}{.}{-1}) sfmt(%6.0fc)
                            }

                            Thanks in advance.
                            Attached Files

                            Comment


                            • #15
                              You need to get the results_*.tex tables from your current directory and compile them. The code in #11 defines the document class and adds some necessary packages to enable you to compile directly. Otherwise, there is no way for me to get what you want just by looking at your code. At a minimum, add a data example that creates some table using your codes if the compilation fails.

                              Comment

                              Working...
                              X