Announcement

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

  • #16
    Yes I have all variables rank1 ... through 21 in the dataset. I use the capture noisily so that if there is no output (as is in the case of some of my communities (demcoms)), the rank value is still created but with a missing value.

    Really the main purpose of creating the different ranks was for the purpose of the coeflab identification. Otherwise they had been all regressing various dependent variables on an independent variable of the same name.

    Comment


    • #17
      In case that wasn't clear. There is one rank per demcom `d'. So there should be a unique identifier for each model.

      Comment


      • #18
        I have simulated a similar dataset. See if this does it.

        Code:
        clear
        set obs 4000
        set seed 08162021
        gen lhs1= rnormal()
        gen visit=runiformint(1,5)
        gen demcom= runiformint(1, 21)
        forval i=1/21{
            g rank`i'= rnormal()
        }
        
        *START HERE
        
        eststo clear
        local prefixes
        local model
        forvalues d=1/21 {
            local model "`model' `" Model `d' "'"
            forvalues v=1/5 {
                preserve
                keep if visit ==  `v'
                keep if demcom == `d' 
                capture noisily reg lhs1 rank`d'
                mat obs= e(b)
                forval i=1/`=colsof(obs)'{
                    mat obs[1, `i']=e(N)
                }
                estadd matrix obs= obs
                eststo `=word("`c(alpha)'", `d')'_`v'
                local prefixes `prefixes' `=word("`c(alpha)'", `d')'
                restore
           }
        }
        
        
        *PROGRAM TO APPEND MODELS
        capt prog drop appendmodelsobs
        *! modification of appendmodels version 1.0.0  14aug2007  Ben Jann
        program appendmodelsobs, eclass
            // using first equation of model
            version 8
            syntax namelist
            tempname b obs V tmp
            foreach name of local namelist {
                qui est restore `name'
                mat `tmp' = e(b)
                local eq1: coleq `tmp'
                gettoken eq1 : eq1
                mat `tmp' = `tmp'[1,"`eq1':"]
                local cons = colnumb(`tmp',"_cons")
                if `cons'<. & `cons'>1 {
                    mat `tmp' = `tmp'[1,1..`cons'-1]
                }
                mat `b' = nullmat(`b') , `tmp'
                mat `tmp' = e(obs)
                local eq1: coleq `tmp'
                gettoken eq1 : eq1
                mat `tmp' = `tmp'[1,"`eq1':"]
                local cons = colnumb(`tmp',"_cons")
                if `cons'<. & `cons'>1 {
                    mat `tmp' = `tmp'[1,1..`cons'-1]
                }
                mat `obs' = nullmat(`obs') , `tmp'
                mat `tmp' = e(V)
                mat `tmp' = `tmp'["`eq1':","`eq1':"]
                if `cons'<. & `cons'>1 {
                    mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
                }
                capt confirm matrix `V'
                if _rc {
                    mat `V' = `tmp'
                }
                else {
                    mat `V' = ///
                    ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
                    ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
                }
            }
            local names: colfullnames `b'
            mat coln `V' = `names'
            mat rown `V' = `names'
            eret post `b' `V'
            mat obs= `obs'
            quietly estadd matrix obs
            eret local cmd "whatever"
        end
        
        local prefixes: list uniq prefixes
        *APPEND THE MODELS
        forval v=1/5{
            local models: subinstr local prefixes " " "_`v' ", all
            eststo M`v': appendmodelsobs `models'_`v'
        }
        
        esttab M*,  cells(b(star fmt(3)) se(par fmt(3)) obs(par([ ]) fmt(a)))  mlab(`model')  collabels(none) ///
        nonum noobs
        Res.:

        Code:
        . esttab M*,  cells(b(star fmt(3)) se(par fmt(3)) obs(par([ ]) fmt(a)))  mlab(`model')  collabels(none) ///
        > nonum noobs
        
        --------------------------------------------------------------------------------------------
                         Model 1         Model 2         Model 3         Model 4         Model 5    
        --------------------------------------------------------------------------------------------
        rank1              -0.056           0.062          -0.121          -0.059           0.039   
                          (0.132)         (0.179)         (0.132)         (0.157)         (0.134)   
                             [43]            [33]            [47]            [34]            [38]   
        rank2              -0.208          -0.178           0.237          -0.057          -0.202   
                          (0.181)         (0.218)         (0.171)         (0.165)         (0.198)   
                             [35]            [36]            [34]            [36]            [36]   
        rank3              -0.045          -0.072          -0.129          -0.100           0.342   
                          (0.174)         (0.175)         (0.118)         (0.156)         (0.215)   
                             [39]            [36]            [39]            [37]            [44]   
        rank4               0.022           0.146           0.047          -0.041          -0.034   
                          (0.162)         (0.152)         (0.125)         (0.170)         (0.198)   
                             [46]            [48]            [44]            [42]            [31]   
        rank5              -0.004           0.234           0.002          -0.169           0.293   
                          (0.223)         (0.136)         (0.188)         (0.146)         (0.185)   
                             [33]            [48]            [32]            [37]            [35]   
        rank6               0.206          -0.254           0.083           0.193          -0.083   
                          (0.164)         (0.189)         (0.156)         (0.215)         (0.178)   
                             [39]            [30]            [44]            [33]            [37]   
        rank7               0.191           0.054           0.056          -0.092          -0.076   
                          (0.149)         (0.181)         (0.144)         (0.144)         (0.143)   
                             [39]            [40]            [42]            [46]            [40]   
        rank8               0.014          -0.071          -0.181           0.131          -0.031   
                          (0.134)         (0.162)         (0.138)         (0.161)         (0.174)   
                             [40]            [33]            [43]            [44]            [32]   
        rank9              -0.171           0.221          -0.177          -0.107          -0.021   
                          (0.131)         (0.145)         (0.159)         (0.140)         (0.163)   
                             [41]            [45]            [37]            [45]            [34]   
        rank10             -0.365*         -0.086          -0.260          -0.057           0.108   
                          (0.148)         (0.172)         (0.147)         (0.192)         (0.145)   
                             [35]            [38]            [38]            [34]            [36]   
        rank11             -0.018          -0.123           0.038           0.089           0.194   
                          (0.131)         (0.161)         (0.122)         (0.153)         (0.251)   
                             [36]            [44]            [62]            [30]            [33]   
        rank12             -0.100           0.053           0.061           0.187          -0.162   
                          (0.141)         (0.129)         (0.148)         (0.129)         (0.128)   
                             [42]            [27]            [53]            [41]            [35]   
        rank13             -0.063          -0.114          -0.106          -0.063          -0.102   
                          (0.144)         (0.124)         (0.134)         (0.179)         (0.215)   
                             [44]            [36]            [41]            [34]            [40]   
        rank14              0.097           0.132           0.072           0.124          -0.086   
                          (0.238)         (0.148)         (0.166)         (0.188)         (0.172)   
                             [32]            [43]            [34]            [39]            [41]   
        rank15             -0.162          -0.213          -0.117          -0.109           0.244   
                          (0.179)         (0.199)         (0.110)         (0.170)         (0.152)   
                             [41]            [35]            [45]            [27]            [43]   
        rank16             -0.084           0.030          -0.106           0.038           0.202   
                          (0.140)         (0.136)         (0.179)         (0.143)         (0.165)   
                             [38]            [39]            [38]            [33]            [34]   
        rank17              0.150           0.096           0.032           0.117           0.004   
                          (0.241)         (0.178)         (0.141)         (0.257)         (0.139)   
                             [33]            [32]            [42]            [36]            [41]   
        rank18             -0.030          -0.052          -0.043          -0.221          -0.124   
                          (0.197)         (0.140)         (0.139)         (0.162)         (0.211)   
                             [44]            [46]            [35]            [32]            [32]   
        rank19             -0.185          -0.082           0.169          -0.107           0.066   
                          (0.142)         (0.179)         (0.154)         (0.177)         (0.226)   
                             [39]            [38]            [31]            [34]            [30]   
        rank20             -0.002           0.404**         0.125           0.136           0.094   
                          (0.141)         (0.152)         (0.149)         (0.154)         (0.214)   
                             [46]            [36]            [29]            [50]            [40]   
        rank21             -0.330           0.086           0.064           0.016           0.405   
                          (0.222)         (0.141)         (0.152)         (0.180)         (0.237)   
                             [28]            [32]            [36]            [37]            [33]   
        --------------------------------------------------------------------------------------------

        Comment


        • #19
          On the added note, use the -addnote()- option and split the text over several lines, where a line is enclosed within double quotes( "line1" "line2" ...). Added to the example in #18, the command and table are

          Code:
          esttab M*, cells(b(star fmt(3)) se(par fmt(3)) obs(par([ ]) fmt(a))) mlab(`model') collabels(none) ///
          nonum noobs addnote("Note: *p$<$0.1, **p$<$0.05, ***p$<$0.01. Standard errors in parentheses. Observation count" ///
          "in brackets. Triplet 1 is Communities 1 \&2, Triplet 2 is Communities 5 \&6 and a Triplet 3" "is Communities 8 \&9.") 
          Code:
          . esttab M*, cells(b(star fmt(3)) se(par fmt(3)) obs(par([ ]) fmt(a))) mlab(`model') collabels(none) ///
          > nonum noobs addnote("Note: *p$<$0.1, **p$<$0.05, ***p$<$0.01. Standard errors in parentheses. Observation count" ///
          > "in brackets. Triplet 1 is Communities 1 \&2, Triplet 2 is Communities 5 \&6 and a Triplet 3" "is Communities 8 \&9.")
          
          --------------------------------------------------------------------------------------------
                           Model 1         Model 2         Model 3         Model 4         Model 5    
          --------------------------------------------------------------------------------------------
          rank1              -0.056           0.062          -0.121          -0.059           0.039  
                            (0.132)         (0.179)         (0.132)         (0.157)         (0.134)  
                               [43]            [33]            [47]            [34]            [38]  
          rank2              -0.208          -0.178           0.237          -0.057          -0.202  
                            (0.181)         (0.218)         (0.171)         (0.165)         (0.198)  
                               [35]            [36]            [34]            [36]            [36]  
          rank3              -0.045          -0.072          -0.129          -0.100           0.342  
                            (0.174)         (0.175)         (0.118)         (0.156)         (0.215)  
                               [39]            [36]            [39]            [37]            [44]  
          rank4               0.022           0.146           0.047          -0.041          -0.034  
                            (0.162)         (0.152)         (0.125)         (0.170)         (0.198)  
                               [46]            [48]            [44]            [42]            [31]  
          rank5              -0.004           0.234           0.002          -0.169           0.293  
                            (0.223)         (0.136)         (0.188)         (0.146)         (0.185)  
                               [33]            [48]            [32]            [37]            [35]  
          rank6               0.206          -0.254           0.083           0.193          -0.083  
                            (0.164)         (0.189)         (0.156)         (0.215)         (0.178)  
                               [39]            [30]            [44]            [33]            [37]  
          rank7               0.191           0.054           0.056          -0.092          -0.076  
                            (0.149)         (0.181)         (0.144)         (0.144)         (0.143)  
                               [39]            [40]            [42]            [46]            [40]  
          rank8               0.014          -0.071          -0.181           0.131          -0.031  
                            (0.134)         (0.162)         (0.138)         (0.161)         (0.174)  
                               [40]            [33]            [43]            [44]            [32]  
          rank9              -0.171           0.221          -0.177          -0.107          -0.021  
                            (0.131)         (0.145)         (0.159)         (0.140)         (0.163)  
                               [41]            [45]            [37]            [45]            [34]  
          rank10             -0.365*         -0.086          -0.260          -0.057           0.108  
                            (0.148)         (0.172)         (0.147)         (0.192)         (0.145)  
                               [35]            [38]            [38]            [34]            [36]  
          rank11             -0.018          -0.123           0.038           0.089           0.194  
                            (0.131)         (0.161)         (0.122)         (0.153)         (0.251)  
                               [36]            [44]            [62]            [30]            [33]  
          rank12             -0.100           0.053           0.061           0.187          -0.162  
                            (0.141)         (0.129)         (0.148)         (0.129)         (0.128)  
                               [42]            [27]            [53]            [41]            [35]  
          rank13             -0.063          -0.114          -0.106          -0.063          -0.102  
                            (0.144)         (0.124)         (0.134)         (0.179)         (0.215)  
                               [44]            [36]            [41]            [34]            [40]  
          rank14              0.097           0.132           0.072           0.124          -0.086  
                            (0.238)         (0.148)         (0.166)         (0.188)         (0.172)  
                               [32]            [43]            [34]            [39]            [41]  
          rank15             -0.162          -0.213          -0.117          -0.109           0.244  
                            (0.179)         (0.199)         (0.110)         (0.170)         (0.152)  
                               [41]            [35]            [45]            [27]            [43]  
          rank16             -0.084           0.030          -0.106           0.038           0.202  
                            (0.140)         (0.136)         (0.179)         (0.143)         (0.165)  
                               [38]            [39]            [38]            [33]            [34]  
          rank17              0.150           0.096           0.032           0.117           0.004  
                            (0.241)         (0.178)         (0.141)         (0.257)         (0.139)  
                               [33]            [32]            [42]            [36]            [41]  
          rank18             -0.030          -0.052          -0.043          -0.221          -0.124  
                            (0.197)         (0.140)         (0.139)         (0.162)         (0.211)  
                               [44]            [46]            [35]            [32]            [32]  
          rank19             -0.185          -0.082           0.169          -0.107           0.066  
                            (0.142)         (0.179)         (0.154)         (0.177)         (0.226)  
                               [39]            [38]            [31]            [34]            [30]  
          rank20             -0.002           0.404**         0.125           0.136           0.094  
                            (0.141)         (0.152)         (0.149)         (0.154)         (0.214)  
                               [46]            [36]            [29]            [50]            [40]  
          rank21             -0.330           0.086           0.064           0.016           0.405  
                            (0.222)         (0.141)         (0.152)         (0.180)         (0.237)  
                               [28]            [32]            [36]            [37]            [33]  
          --------------------------------------------------------------------------------------------
          Note: *p$<$0.1, **p$<$0.05, ***p$<$0.01. Standard errors in parentheses. Observation count
          in brackets. Triplet 1 is Communities 1 \&2, Triplet 2 is Communities 5 \&6 and a Triplet 3
          is Communities 8 \&9.
          Last edited by Andrew Musau; 16 Aug 2021, 13:12.

          Comment


          • #20
            Ahh. I had tried the double "", but perhaps bobbled up the ///. Thanks tremendously, as always. I will amend this tomorrow to fit my code and post a response (hopefully with victory and not another question!) Many thanks. Will get back to you.

            Comment


            • #21
              Hi Andrew, I think we had the same method for the long footnote. I put the table into LaTeX (again, my enormous thanks for your truly amazing help) - but I am still getting the column misalignment due to the long footnotes. Let me demonstrate with this photo.

              Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	19.7 KB
ID:	1623655

              Comment


              • #22
                Did you change -note()- to -addnote()-? It's a subtle but important difference. Also, if esttab does not automatically add linebreaks, add these yourself. In LaTeX, these are included as a double backslash (\\).

                EDITED: This example shows that esttab does indeed add the line breaks.

                Code:
                sysuse auto, clear
                regress mpg weight
                esttab, addnote("line1""line2""line3") tex
                Res.:

                Code:
                . esttab, addnote("line1""line2""line3") tex
                
                {
                \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
                \begin{tabular}{l*{1}{c}}
                \hline\hline
                            &\multicolumn{1}{c}{(1)}\\
                            &\multicolumn{1}{c}{mpg}\\
                \hline
                weight      &    -0.00601\sym{***}\\
                            &    (-11.60)         \\
                [1em]
                \_cons      &       39.44\sym{***}\\
                            &     (24.44)         \\
                \hline
                \(N\)       &          74         \\
                \hline\hline
                \multicolumn{2}{l}{\footnotesize \textit{t} statistics in parentheses}\\
                \multicolumn{2}{l}{\footnotesize line1}\\
                \multicolumn{2}{l}{\footnotesize line2}\\
                \multicolumn{2}{l}{\footnotesize line3}\\
                \multicolumn{2}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
                \end{tabular}
                }

                Try splitting the notes over more lines.
                Last edited by Andrew Musau; 17 Aug 2021, 07:07.

                Comment


                • #23
                  I did ... I did exactly as you said.

                  Comment


                  • #24
                    I can reproduce your issue. Just split the notes over several lines.

                    Code:
                    clear
                    set obs 4000
                    set seed 08162021
                    gen lhs1= rnormal()
                    gen visit=runiformint(1,5)
                    gen demcom= runiformint(1, 21)
                    forval i=1/21{
                        g rank`i'= rnormal()
                    }
                    
                    *START HERE
                    
                    eststo clear
                    local prefixes
                    local model
                    forvalues d=1/21 {
                        local model "`model' `" Model `d' "'"
                        forvalues v=1/5 {
                            preserve
                            keep if visit ==  `v'
                            keep if demcom == `d'
                            capture noisily reg lhs1 rank`d'
                            mat obs= e(b)
                            forval i=1/`=colsof(obs)'{
                                mat obs[1, `i']=e(N)
                            }
                            estadd matrix obs= obs
                            eststo `=word("`c(alpha)'", `d')'_`v'
                            local prefixes `prefixes' `=word("`c(alpha)'", `d')'
                            restore
                       }
                    }
                    
                    
                    *PROGRAM TO APPEND MODELS
                    capt prog drop appendmodelsobs
                    *! modification of appendmodels version 1.0.0  14aug2007  Ben Jann
                    program appendmodelsobs, eclass
                        // using first equation of model
                        version 8
                        syntax namelist
                        tempname b obs V tmp
                        foreach name of local namelist {
                            qui est restore `name'
                            mat `tmp' = e(b)
                            local eq1: coleq `tmp'
                            gettoken eq1 : eq1
                            mat `tmp' = `tmp'[1,"`eq1':"]
                            local cons = colnumb(`tmp',"_cons")
                            if `cons'<. & `cons'>1 {
                                mat `tmp' = `tmp'[1,1..`cons'-1]
                            }
                            mat `b' = nullmat(`b') , `tmp'
                            mat `tmp' = e(obs)
                            local eq1: coleq `tmp'
                            gettoken eq1 : eq1
                            mat `tmp' = `tmp'[1,"`eq1':"]
                            local cons = colnumb(`tmp',"_cons")
                            if `cons'<. & `cons'>1 {
                                mat `tmp' = `tmp'[1,1..`cons'-1]
                            }
                            mat `obs' = nullmat(`obs') , `tmp'
                            mat `tmp' = e(V)
                            mat `tmp' = `tmp'["`eq1':","`eq1':"]
                            if `cons'<. & `cons'>1 {
                                mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
                            }
                            capt confirm matrix `V'
                            if _rc {
                                mat `V' = `tmp'
                            }
                            else {
                                mat `V' = ///
                                ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
                                ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
                            }
                        }
                        local names: colfullnames `b'
                        mat coln `V' = `names'
                        mat rown `V' = `names'
                        eret post `b' `V'
                        mat obs= `obs'
                        quietly estadd matrix obs
                        eret local cmd "whatever"
                    end
                    
                    local prefixes: list uniq prefixes
                    *APPEND THE MODELS
                    forval v=1/5{
                        local models: subinstr local prefixes " " "_`v' ", all
                        eststo M`v': appendmodelsobs `models'_`v'
                    }
                    
                    
                    esttab M* using mytable.tex, replace cells(b(star fmt(3)) se(par fmt(3)) obs(par([ ]) fmt(a))) mlab(`model') collabels(none) ///
                    nonum noobs addnote("Note: *p$<$0.1, **p$<$0.05, ***p$<$0.01. Standard errors in" ///
                    "parentheses. Observation count in brackets. Triplet 1 is" ///
                     "Communities 1 \&2, Triplet 2 is Communities 5 \&6 and a" ///
                     "Triplet 3 is Communities 8 \&9.")
                    
                    // 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{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
                    Res.:
                    Click image for larger version

Name:	Screenshot 2021-08-17 143359.png
Views:	1
Size:	106.4 KB
ID:	1623672

                    Comment


                    • #25
                      Yeah, I can't get it. Right now when I am putting into LaTeX I have a simple \input{table.tex} - I might look into adding the footnotes in LaTeX, after the table, rather than within the table? This feels so dumb but I know will save me hours and hours in the future as we refine our numbers.

                      Comment


                      • #26
                        Do you do that temp writing at the top and bottom of the file everytime? I am unfamiliar with that.

                        Comment


                        • #27
                          I might look into adding the footnotes in LaTeX, after the table, rather than within the table?
                          It may be easier in the longer run rather than trying to figure out alignment. That is what I usually do.

                          Do you do that temp writing at the top and bottom of the file every time? I am unfamiliar with that.
                          No, this is just to generate a ready to run table. I usually run esttab with the -tex- option and then copy and paste the table to my LaTeX document.

                          Comment


                          • #28
                            Originally posted by Andrew Musau View Post

                            It may be easier in the longer run rather than trying to figure out alignment. That is what I usually do.



                            No, this is just to generate a ready to run table. I usually run esttab with the -tex- option and then copy and paste the table to my LaTeX document.
                            Ohhhh. Ok. Well, that's helpful to know. Yes, I agree sometime latex wraparounds the obvious way to go. Will try and get this to run what you sent sans footnote and post once (hopefully!) sorted.

                            Comment


                            • #29
                              GOT IT. Andrew, you are amazing. In the end I managed to sort the observations. If anyone has been following this long exchange, I hope you find this helpful in your quest for automatic tables.

                              Code:
                              gen     lhs11= rnormal()
                              drop     lhs1
                              rename     lhs11    lhs1
                              gen     visit1=runiformint(1, 5)
                              drop    visit
                              rename    visit1 visit
                              gen     demcom1= runiformint(1, 21)
                              drop    demcom
                              rename    demcom1 demcom
                              order     lhs1 visit demcom
                              forval i=1/21{
                                  g         rank`i'11= rnormal()
                                  drop     rank`i'
                                  rename     rank`i'11 rank`i'
                              }
                              
                              *START HERE
                              
                              eststo clear
                              local prefixes
                              local model
                              local z "1 2 5 6 8 9 10 11"
                              foreach d of local z {
                                  local model "`model' `" Model `d' "'"
                                  forvalues v=1/5 {
                                      preserve
                                      keep if visit ==  `v'
                                      keep if demcom == `d'
                                      capture noisily reg lhs1 rank`d'
                                      mat obs= e(b)
                                      forval i=1/`=colsof(obs)'{
                                          mat obs[1, `i']=e(N)
                                      }
                                      estadd matrix obs= obs
                                      eststo `=word("`c(alpha)'", `d')'_`v'
                                      local prefixes `prefixes' `=word("`c(alpha)'", `d')'
                                      restore
                                 }
                              }
                              
                              
                              *PROGRAM TO APPEND MODELS
                              capt prog drop appendmodelsobs
                              *! modification of appendmodels version 1.0.0  14aug2007  Ben Jann
                              program appendmodelsobs, eclass
                                  // using first equation of model
                                  version 8
                                  syntax namelist
                                  tempname b obs V tmp
                                  foreach name of local namelist {
                                      qui est restore `name'
                                      mat `tmp' = e(b)
                                      local eq1: coleq `tmp'
                                      gettoken eq1 : eq1
                                      mat `tmp' = `tmp'[1,"`eq1':"]
                                      local cons = colnumb(`tmp',"_cons")
                                      if `cons'<. & `cons'>1 {
                                          mat `tmp' = `tmp'[1,1..`cons'-1]
                                      }
                                      mat `b' = nullmat(`b') , `tmp'
                                      mat `tmp' = e(obs)
                                      local eq1: coleq `tmp'
                                      gettoken eq1 : eq1
                                      mat `tmp' = `tmp'[1,"`eq1':"]
                                      local cons = colnumb(`tmp',"_cons")
                                      if `cons'<. & `cons'>1 {
                                          mat `tmp' = `tmp'[1,1..`cons'-1]
                                      }
                                      mat `obs' = nullmat(`obs') , `tmp'
                                      mat `tmp' = e(V)
                                      mat `tmp' = `tmp'["`eq1':","`eq1':"]
                                      if `cons'<. & `cons'>1 {
                                          mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
                                      }
                                      capt confirm matrix `V'
                                      if _rc {
                                          mat `V' = `tmp'
                                      }
                                      else {
                                          mat `V' = ///
                                          ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
                                          ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
                                      }
                                  }
                                  local names: colfullnames `b'
                                  mat coln `V' = `names'
                                  mat rown `V' = `names'
                                  eret post `b' `V'
                                  mat obs= `obs'
                                  quietly estadd matrix obs
                                  eret local cmd "whatever"
                              end
                              
                              local prefixes: list uniq prefixes
                              *APPEND THE MODELS
                              forval v=1/5{
                                  local models: subinstr local prefixes " " "_`v' ", all
                                  eststo M`v': appendmodelsobs `models'_`v'
                              }
                              
                              
                              esttab M* using D:\Dropbox\2021\health_inequities\hiv_ci_treated.tex , cells(b(star fmt(3)) se(par fmt(3)) obs(par([ ]) fmt(a))) mlabels("(W1)" "(W2)" "(W3)" "(W4)" "(W2-4)")  title("HIV Prevalence Concentration Index by Wave -- Treated (Zambia)") ///
                              addnotes("Notes: *p$<$0.1, **p$<$0.05, ***p$<$0.01. Standard errors in parentheses." "Observation count in brackets." "Triplet 1 is Communities 1\&2, Triplet 2 is Communities 5\&6,""Triplet 3 is Communities 8\&9, and Triplet 4 is Communities 10\&11.") ///
                              collabels(none) coeflab(rank1 "Community 1" rank2 "Community 2" rank5 "Community 5" rank6 "Community 6" rank8 "Community 8" rank9 "Community 9" rank10 "Community 10" rank11 "Community 11") nonumbers noobs replace
                              Attached Files
                              Last edited by Christa Hansen; 17 Aug 2021, 10:32.

                              Comment

                              Working...
                              X