Announcement

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

  • Printing out balance table

    EDIT: Formatting of tables and code in this post got messed up. View my post below to see correct format of tables and code.

    I have an assignment in which I need to print out a table of the following form:
    pre_verb
    pre_math
    pre_tot
    male
    Where diff is the difference between treatment and control group, and the p-value is the p-value of the difference.
    So far what I've got is

    /* Creating balance table */ sort treatment by treatment: eststo: quietly estpost summarize pre_verb pre_math pre_tot male, listwise esttab, cells("mean sd") label nodepvar This outputs:
    pre_verb x x x x
    pre_math x x x x
    pre_tot x x x x
    male x x x x
    (x=data irrelevant for the question)
    I'm having trouble with finding commands as to just print out the SE of the difference (i.e. one SE) as well as the difference between the means and the p-value. I've been googling for hours to try and find a solution but without luck.
    Any tips?

    Last edited by Gustav Kaller; 04 Feb 2021, 10:16.

  • #2
    The formatting of the post seems to have been a bit messed up. Here is the correct tables and code:

    Table that I want:
    Control Treatment Diff. SE P-value
    pre_verb
    pre_math
    pre_tot
    male
    Code:
    Code:
    /* Creating balance table */
    
    sort treatment
    
    by treatment: eststo: quietly estpost summarize pre_verb pre_math pre_tot male, listwise
    
    esttab, cells("mean sd") label nodepvar
    Table that I get:
    mean sd mean sd
    pre_verb
    pre_math
    pre_tot
    male

    Comment


    • #3
      your question is a bit unclear but I think if you do a t-test you can get everything you want saved and just grab it; try a t-test and then type
      Code:
      return li

      Comment


      • #4
        Originally posted by Rich Goldstein View Post
        your question is a bit unclear but I think if you do a t-test you can get everything you want saved and just grab it; try a t-test and then type
        Code:
        return li
        Thank you for your response. Basically what I'm after is a table similar to the one below. The means on a control and a treatment group, the difference of said mean, the standard error and the p-value of the difference in the column and a couple of other variables on the rows as shown in my previous post. I'm having issues with finding a way to get the mean difference, the standard error and the p-value of the difference into the columns. I'm still learning Stata and I can't seem to find any code to make it as such:

        Comment


        • #5
          I don't see that this has anything to do with "balance" but there are a number of user-written programs that should help; here are some, off the top of my head, but there are others also; for each, use search to find and install: table1_mc, basetable, baselinetable

          Comment


          • #6
            I'm not aware of a Stata command that does exactly what you want. If there isn't one, what Rich meant in post #3 was that if you use the native commands putexcel and ttest, you can get this table together if you are able to pre-plan your Excel sheet.

            Whenever you run an estimation command, it leaves behind a few virtual variables and/or matrices. If you type return list after a t-test, you will see several virtual variables (called scalars), e.g. r(N_1) is the sample size of group 1, r(mu_1) is the mean for group 1, r(p) is the p-value, r(se) is the standard error.

            Here's some discussion on the Stata blog. For your case, you could type something like

            Code:
            putexcel set table1
            ttest school_open, by(treatment)
            scalar dif = r(mu_1) - r(mu_2)
            scalar N = r(N_1) + r(N_2)
            putexcel A2 = "Panel A. Teacher attendance"
            putexcel A3 = "School Open"
            putexcel B2 = (r(mu_1))
            putexcel C2 = (r(mu_2))
            putexcel D2 = (dif)
            putexcel D3 = (r(se))
            putexcel B4 = (r(N_1))
            putexcel C4 = (r(N_2))
            putexcel D4 = (N)
            You can even use putexcel to write in the header rows. I am pretty sure you can mock up the table skeleton, put it in your working directory, and then have putexcel write the values. You just have to plan the table out beforehand.
            Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

            When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

            Comment


            • #7
              I am looking to produce a similar table and have found the following website very useful in doing so.
              https://hofmanpaul.com/automation/de...bles-in-stata/

              Comment

              Working...
              X