Announcement

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

  • Stacking tabulate tables into a large table with est

    I've successfully generate a set of descriptive tables for six variables, and I can manually stack them on top of each other, but would like to know if there's a way to automate this. This is what my code currently looks like:

    Code:
    . eststo clear
    . eststo: quietly estpost svy: tabulate ageG22 if Md1sample==1
    . esttab, cell("b(f(4))") varlabels(`e(labels)') varwidth(16)
    . eststo: quietly estpost svy: tabulate genderC if Md1sample==1
    . esttab, cell("b(f(4))") varlabels(`e(labels)') varwidth(16)
    . quietly estpost svy: tabulate raceD if Md1sample==1
    . esttab, cell("b(f(4))") varlabels(`e(labels)') varwidth(16)
    . quietly estpost svy: tabulate relcat if Md1sample==1
    . esttab, cell("b(f(4))") varlabels(`e(labels)') varwidth(16)
    . quietly estpost svy: tabulate educ_par1 if Md1sample==1
    . esttab, cell("b(f(4))") varlabels(`e(labels)') varwidth(25)
    . quietly estpost svy: tabulate educ_par1 if Md1sample==1
    . esttab, cell("b(f(4))") varlabels(`e(labels)') varwidth(25)
    ageG22 genderC raceD and so on are the variables being tabulated. Ideally, the column total would be eliminated from each tabulation, and I would get one long table with value label on the left and the proportion on the right.

    Thanks
    Chris

  • #2
    Here is an example of what you are looking for:
    Code:
    webuse nhanes2f
    svyset psuid [pweight=finalwgt], strata(stratid)
    eststo clear
    foreach i of var agegrp female race {
     eststo: estpost svy: tabulate `i' 
     esttab using myfile.csv, cell("b(f(4))") varlabels(`e(labels)') varwidth(16) app
     eststo clear 
    }

    Comment


    • #3
      Thank you. Is there a way to suppress (1), "Mean" "b", and the total on the right side; and add the variable name on the left side? Currently the first few rows of the Excel sheet look like this

      (1)
      Mean
      b
      Male 0.4424
      Female 0.5480
      Trans/Other 0.0096
      Total 1.0000
      N 18527
      (1)
      Mean
      b
      Non-Hisp. White 0.6825
      Hisp. White 0.0520
      Hispanic Only 0.0293


      I'm not sure if it's possible but I'd like to generate something like this:

      Gender
      Male 0.4424
      Female 0.5480
      Trans/Other 0.0096
      Race
      Non-Hisp. White 0.6825
      Hisp. White 0.0520
      Hispanic Only 0.0293

      Comment


      • #4
        Sorry I realize that didn't post correctly. Here's what I meant to paste:
        Code:
                            (1)
                            Mean
                            b
        Male                0.4424
        Female              0.5480
        Trans/Other         0.0096
        Total               1.0000
        N                   18527
                            (1)
                            Mean
                            b
        Non-Hisp. White     0.6825
        Hisp. White         0.0520
        Hispanic Only       0.0293
        And this is what I want:
        Code:
        Gender    
        Male                0.4424
        Female              0.5480
        Trans/Other         0.0096
        Race    
        Non-Hisp. White     0.6825
        Hisp. White         0.0520
        Hispanic Only       0.0293

        Comment


        • #5
          I think that will do the trick. You should read the help file of esttab and this website where you'll find many examples:
          Code:
          webuse nhanes2f, clear
          svyset psuid [pweight=finalwgt], strata(stratid)
          
          label var agegrp "Age groups"
          label var sex "Sex"
          label var race "Race"
          eststo clear
          
          foreach i of var agegrp sex race {
           eststo: estpost svy: tabulate `i' 
           esttab using myfile.csv, cells("b(label(`: var label `i'')fmt(4))")  mtitle("") nonumber noobs app
           eststo clear 
          }

          Comment


          • #6
            Thanks. That takes away the serial number and "Mean" but still leaves b and there's no column title. I also get the recurring message
            Code:
            row labels saved in macro e(labels)
            (est1 stored)
            nothing found where name expected
            (output written to myfile.csv)
            Despite the message I do get a csv file that's easier to manually edit. I've read the esttab website but I'll have a look again.

            Comment


            • #7
              I can't reproduce your example. When I run the code in #5 this is the results I get, which is very similar for what you are asking for:
              Code:
               
              Age groups
              age20-29 0.2808
              age30-39 0.2045
              age40-49 0.1683
              age50-59 0.1670
              age60-69 0.1332
              age 70+ 0.0462
              Total 1.0000
              Sex
              Male 0.4796
              Female 0.5204
              Total 1.0000
              Race
              White 0.8790
              Black 0.0956
              Other 0.0254
              Total 1.0000
              Please show us exactly what you typed and what Stata gave you back.

              Comment

              Working...
              X