Announcement

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

  • Exporting simple diff-in-diff table

    I am trying to export a simple diff-in-diff table. I have included a sample of data down below.

    I have tried the "diff" command and the "ieddtab" command. They require outside download, ssc install diff & ssc install ietoolkit


    Below, I have an example of the simple DiD table I like and an attempted export. The export "runs" but it looks terrible and is not readable.
    Does anyone have a good go-to command they use when exporting these kinds of simple tables?


    ieddtab in_laborforce, time(survey_1998) treatment(treat)

    asdoc ieddtab in_laborforce, time(survey_1998) treatment(treat), save(simple_DiD.doc)


    clear
    input float(in_laborforce treat control survey_1998)
    0 0 1 0
    0 0 1 0
    0 1 0 0
    0 1 0 0
    0 0 1 0
    1 0 1 0
    1 1 0 0
    0 0 1 0
    0 0 1 0
    0 0 1 0
    1 1 0 1
    0 0 1 1
    0 0 1 1
    1 1 0 1
    1 0 1 1
    1 0 1 1
    1 1 0 0
    1 0 1 0
    1 0 1 0
    1 0 1 0
    1 1 0 0
    1 0 1 0
    1 0 1 0
    0 1 0 0
    0 1 0 0
    0 0 1 0
    1 0 1 1
    0 0 1 1
    0 0 1 1
    0 0 1 1
    0 0 1 1
    0 0 1 1
    1 1 0 1
    0 1 0 1
    end



  • #2
    Since the two programs you have mentioned are not Stata official programs, asdoc (available on SSC) is not aware of them. Therefore, asdoc tries to export the results of these programs from a log file, which is off course not pretty in this case. The program ieddtab leaves behind a matrix ieddtabResults of all the results, but that is also not well formatted matrix for creating a nice table. For example :
    Code:
    ssc install asdoc
    ieddtab in_laborforce, time(survey_1998) treatment(treat)
    mat table =  r(ieddtabResults)
    matlist table
     matlist table
    
                 | in_labo~e
    -------------+-----------
              2D |   .482967
          2D_err |  .3847713
        2D_stars |         0
            2D_N |        34
         2D_clus |         .
             1DC | -.1615385
         1DC_err |  .2119227
       1DC_stars |         0
           1DC_N |        23
        1DC_clus |         .
             1DT |  .3214286
         1DT_err |  .3279757
       1DT_stars |         0
           1DT_N |        11
        1DT_clus |         .
         C0_mean |  .4615385
          C0_err |  .1439099
            C0_N |        13
         C0_clus |         .
         T0_mean |  .4285714
          T0_err |  .2020305
            T0_N |         7
         T0_clus |         .
         C1_mean |        .3
          C1_err |  .1527525
            C1_N |        10
         C1_clus |         .
         T0_mean |       .75
          T0_err |       .25
            T0_N |         4
         T0_clus |         .
    If you want to export this matrix, you can try this code:
    Code:
    asdoc wmat, mat(table) replace
    If this template is what you frequently use, then I think you can go for asdocx where making a customized template file is a good investment.
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment


    • #3

      If this template is what you frequently use, then I think you can go for asdocx where making a customized template file is a good investment.
      I'm not married to this format. If you know of a way to export a table created with the "diff" command that would also be great. Or really anyway of exporting a simple nice diff-in-diff table

      Code:
      diff in_laborforce, t(treat) p(survey_1998)

      Comment


      • #4
        Have you tried the examle used in the diff (SSC) helpfile using outreg2 (SSC)

        Code:
        diff in_laborforce,  period(survey_1998) treated(treat)
        
        
        
        outreg2 using table_diff, ctitle(`r(depvar)') addstat(Mean control t(0), r(mean_c0), Mean treated t(0), r(mean_t0), Diff t(0), r(diff0), Mean control t(1), r(mean_c1), ///
             Mean treated t(1), r(mean_t1), Diff t(1), r(diff1)) label word excel keep(_diff) nocons
        Click image for larger version

Name:	Screen Shot 2021-02-04 at 1.27.01 PM.png
Views:	1
Size:	393.4 KB
ID:	1592900

        Comment


        • #5
          Originally posted by Justin Blasongame View Post
          Have you tried the examle used in the diff (SSC) helpfile using outreg2 (SSC)
          Yea, I did try that and it "works" but it doesn't look like the classic table we've all seen. I included what I am thinking of below

          Comment


          • #6
            Code:
            collapse (mean) in_laborforce, by(survey_1998 treat)
            reshape wide in_laborforce, i(treat) j(survey_1998)
            
            gen diff = in_laborforce1 - in_laborforce0
            set obs `=_N+1'
            
            ds treat, not 
            foreach v in `r(varlist)'  {
                replace `v' = `v'[2] - `v'[1] in `=_N'
            }
            drop treat
            ren (in_laborforce0 in_laborforce1) (before after)
            gen per = ""
            replace per = cond(_n == 1, "Control", cond(_n == 2, "Treatment", "Difference"),"Difference")
            order per 
            
            
            . list , div noobs
            
              +-------------------------------------------+
              |        per |   before | after |      diff |
              |------------+----------+-------+-----------|
              |    Control | .4615385 |    .3 | -.1615385 |
              |  Treatment | .4285714 |   .75 |  .3214286 |
              | Difference | -.032967 |   .45 |   .482967 |
              +-------------------------------------------+
            And for reference
            Code:
            diff in_laborforce,  period(survey_1998) treated(treat)
            
            DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS
            Number of observations in the DIFF-IN-DIFF: 34
                        Before         After    
               Control: 13             10          23
               Treated: 7              4           11
                        20             14
            --------------------------------------------------------
             Outcome var.   | in_la~e | S. Err. |   |t|   |  P>|t|
            ----------------+---------+---------+---------+---------
            Before          |         |         |         | 
               Control      | 0.462   |         |         | 
               Treated      | 0.429   |         |         | 
               Diff (T-C)   | -0.033  | 0.239   | -0.14   | 0.891
            After           |         |         |         | 
               Control      | 0.300   |         |         | 
               Treated      | 0.750   |         |         | 
               Diff (T-C)   | 0.450   | 0.302   | 1.49    | 0.146
                            |         |         |         | 
            Diff-in-Diff    | 0.483   | 0.385   | 1.26    | 0.219
            --------------------------------------------------------
            R-square:    0.07
            * Means and Standard Errors are estimated by linear regression
            **Inference: *** p<0.01; ** p<0.05; * p<0.1

            Comment


            • #7
              Wow, that looks great! I had feared that the best way to make this would be using the collapse command. So odd that there are commands for making these tables but not for exporting them!

              Comment

              Working...
              X