Announcement

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

  • tabstat+estout

    Hi everyone, I am trying to have some descriptive statistics on time children spend with their own parents using Italian Time Use Data and I am using tabstat+estout. Is there a way to put the standard deviation under the mean (i.e. in the same row below the mean and not in another column) in the table output I am exporting? Here is an example of my code:
    Code:
    keep if child==1
    foreach X of varlist read_mother play_mother homework_mother fairytales_mother {
    tabstat `X',  missing stat(n mean sd min max) save
    estpost tabstat `X',  missing stat(n mean sd min max)
    eststo table_1, esample
    estout table_1 using table1.xls,append style(tab) cells((mean(fmt(2)) sd(par fmt(2)) min(fmt(2)) max(fmt(2)))) omitted legend label varlabels(_cons \_cons) title(`X')
    }
    Thank you in advance,
    Andrea

  • #2
    Hi Andrea,

    I refer to the estout part of your code. I simply changed the order of your code. So if you want sd on a different row (and below the mean) just use "cells ((mean min max) sd)"

    Code:
    estout table_1 using table1.xls, append style(tab) cells((mean(fmt(2)) min(fmt(2)) max(fmt(2))) sd(par fmt(2))) omitted legend label varlabels(_cons \_cons) title(`X')
    Dario

    Comment


    • #3
      Thank you very much!

      Comment


      • #4
        Is there any way to get the mean and sd on the same row? No matter what I do (I tried the wide and onecell options), I get the sd on its own row underneath the mean.
        Code:
            eststo sum1: estpost sum $myvarlist if data_round==1
            eststo sum2: estpost sum $myvarlist if data_round==2
            eststo sum3: estpost sum $myvarlist if data_round==3
            eststo sum4a: estpost sum $myvarlist
            esttab sum1 sum2 sum3 sum4 using "table1.rtf", label replace cells(mean(fmt(2)) sd(par)) ///
                mlabels("2010" "2013" "2016/17*" "Overall") title("Summary Statistics, Table 1 replication") ///
                noobs nonumbers wide collabels("Mean (St. Dev)")
            esttab sum1 sum2 sum3a sum4a using "table1A.rtf", label replace cells(mean(fmt(2)) sd(par)) ///
                mlabels("2010" "2013" "2016/17" "Overall") title("Summary Statistics, Table 1A replication") ///
                noobs nonumbers wide collabels("Mean (St. Dev)")
        Thanks so much!
        -Kate

        Comment


        • #5
          estout/ esttab is from Stata Journal / SSC (as you are asked to explain). -cells()- is an estout option, not esttab - and estout takes precedence over esttab. Confusing? Yes, but do read

          Code:
          help estout
          For your immediate problem, you want to put quotation marks around whatever appears within -cells()-

          Code:
          cells("mean(fmt(2)) sd(par)")

          Comment


          • #6
            Thank you! That's so helpful!

            I'm also having trouble getting the median results saved in estpost to actually show up in the table. I'm just getting headings but no rows with the following code, any advice?

            Code:
                eststo sum1: estpost tabstat $conas if data_round==1, stats(median)
                eststo sum2: estpost tabstat $conas if data_round==2, stats(median)
                eststo sum3: estpost tabstat $conas if data_round==3, stats(median)
                eststo sum4: estpost tabstat $conas, stats(median)
                esttab sum1 sum2 sum3 sum4 using "table1_medians.rtf", label replace cells("Median (fmt(2))") ///
                    mlabels("2010" "2013" "2016/17" "Overall") title("Summary Statistics, Table 1 CoNA Medians replication") ///
                    noobs nonumbers

            Comment


            • #7
              The median is the 50th percentile and is thus stored as such. So you want

              Code:
              cells("p50 (fmt(2))")
              The are options to call it whatever you want after outputting, e.g.,

              Code:
              esttab sum1...,  cells("p50 (fmt(2))") nonumbers mtitle(median) collabels(none) compress
              With multiple stats, use collabels("stat1" "stat2" ...).
              Last edited by Andrew Musau; 08 Oct 2019, 15:28.

              Comment


              • #8
                I did try that and it's coming up blank still... bizarre.

                Comment


                • #9
                  How about?

                  Code:
                  eststo sum1: estpost sum $conas if data_round==1, d
                  esttab sum1, cells("p50 (fmt(2))")
                  Otherwise you need to copy and paste the exact commands that you typed and the resulting output.

                  Comment


                  • #10
                    The following code is producing the attached output table. Any ideas would be so much appreciated!

                    Code:
                        eststo sum1: estpost tabstat $conas if data_round==1, stats(p50)
                        eststo sum2: estpost tabstat $conas if data_round==2, stats(p50)
                        eststo sum3: estpost tabstat $conas if data_round==3, stats(p50)
                        eststo sum4: estpost tabstat $conas, stats(p50)
                        esttab sum1 sum2 sum3 sum4 using "medians.rtf", label replace cells("p50 (fmt(2))") ///
                            mlabels("2010" "2013" "2016/17" "Overall") title("Summary Statistics, Medians replication") ///
                            noobs nonumbers
                    Attached Files

                    Comment


                    • #11
                      I don't use tabstat, but I think I see where the problem is. If you use tabstat, you will want to specify each of the variable names contained in the global "$conas" within the -cells()- option of esttab. Otherwise, implement my suggestion in #9 which would have worked fine.

                      Code:
                      eststo sum1: estpost sum $conas if data_round==1, d
                      eststo sum2: estpost sum $conas if data_round==2, d
                      eststo sum3: estpost sum $conas if data_round==3, d
                      eststo sum4: estpost sum $conas, d
                      esttab sum1 sum2 sum3 sum4 using "medians.rtf", label replace cells("p50 (fmt(2))") ///
                      mlabels("2010" "2013" "2016/17" "Overall") title("Summary Statistics, Medians replication") ///
                      noobs nonumbers

                      Comment

                      Working...
                      X