Announcement

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

  • Change the way that esttab present results in csv file

    Hi everyone,

    I got the attached do-file from the former research assistant of the project I work on. As you can see in the csv file attached also, the results of the three different sub-samples the regressions run on are displayed vertically. I want to change the code such that the results from the different sub-samples will appear side by side (with a space column ). If you look at the csv file, I want to eventually get what I will get if I manually copying the cells A:38:D:70 and paste then in F1:I32.

    Can someone please tell me what should I change in the attached code to make it happen?

    Thank you very much,

    best,

    Fitzgerald.
    Attached Files

  • #2
    Please refer to FAQ Advice #12.5 on posting attachments, which states: don't! The best way to get helpful advice is to post a reproducible example of your problem. Otherwise, if you have a multiple-equation model (I can’t tell), consider using the -unstack- option of esttab. Note that estout is from SSC, as you are asked to explain in FAQ Advice #12.

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Please refer to FAQ Advice #12.5 on posting attachments, which states: don't! The best way to get helpful advice is to post a reproducible example of your problem. Otherwise, if you have a multiple-equation model (I can’t tell), consider using the -unstack- option of esttab. Note that estout is from SSC, as you are asked to explain in FAQ Advice #12.
      Okay, my appologize.

      I tried the -unstack- option but it doesn't change anything.

      The relevant code is
      Code:
          esttab using "$path\Analysis\Old\07 July 25 - Itamar\table5_HHI_N1_zipcodes.csv", ///
          se label b(%9.4f) se(%9.4f) star(* 0.10 ** 0.05 *** 0.01) ///
          noomitted nobaselevels nodepvar nomtitles noobs nocon ///
          scalars (p_value_pos_neg p_value_pos_neg_homoge Observations Students) sfmt(%9.4f %9.4f %10.0f %10.0f) ///
          title("`s'") `opt'
      Where `s' are name of the binary variable that identify the subsamples

      Any idea what should I change or add to get side by side results?

      Thanks again,

      Fitz

      Comment


      • #4
        I still need to see the commands leading up to the creation of the table. Then you can also run

        Code:
        esttab, se label b(%9.4f) se(%9.4f) star(* 0.10 ** 0.05 *** 0.01) ///
            noomitted nobaselevels nodepvar nomtitles noobs nocon ///
            scalars (p_value_pos_neg p_value_pos_neg_homoge Observations Students) sfmt(%9.4f %9.4f %10.0f %10.0f) ///
            title("`s'") `opt'
        and copy and paste the resulting table here. It will be displayed on the screen. Post all these within CODE delimiters.

        Comment


        • #5
          Thank you Andrew. This is the full code:

          Originally posted by Andrew Musau View Post
          I still need to see the commands leading up to the creation of the table. Then you can also run

          Code:
          esttab, se label b(%9.4f) se(%9.4f) star(* 0.10 ** 0.05 *** 0.01) ///
          noomitted nobaselevels nodepvar nomtitles noobs nocon ///
          scalars (p_value_pos_neg p_value_pos_neg_homoge Observations Students) sfmt(%9.4f %9.4f %10.0f %10.0f) ///
          title("`s'") `opt'
          and copy and paste the resulting table here. It will be displayed on the screen. Post all these within CODE delimiters.
          This is the code I run:
          Code:
          *** Table 5: The Effect of Teacher Ethics and Homogeneity on Student Exam Dishonesty Across School Sectors  ***
          clear all
          set more off
          cap log close
          
          ********************************************************************************
          * Insert the correct path at the line below:
          global path "D:\School Ethics"
          ********************************************************************************
          
          use "$path\Data\ethics_data_98_02.dta", clear
          
          log using "$path\Analysis\Old\22 June 25  - Itamar\table5_HHI_zipcodes.txt", text replace
          ********************************************************************************
          
          gen ten_positive_wo_extXhomoge = ten_positive_wo_ext * hhi_school_zip
          label var ten_positive_wo_extXhomoge "Positive Ten-Point Difference X School HHI zipcodes Homogeneity Index"
          gen ten_negative_wo_extXhomoge = ten_negative_wo_ext * hhi_school_zip
          label var ten_negative_wo_extXhomoge "Negative Ten-Point Difference X School HHI zipcodes Homogeneity Index"
          
          global stu_chars boy educ_f educ_m
          global subsamples all jewish arab
          
          local i 1
          foreach s in $subsamples{
              preserve
              di "`s'"
              keep if `s' == 1
              eststo clear
          
              * Column 1: Cohort and Exam Period FE, Gender and Parents Schooling, Exam Code FE, Student FE
              eststo: reghdfe disqualified ten_positive_wo_ext ten_negative_wo_ext ///
              ten_positive_wo_extXhomoge ten_negative_wo_extXhomoge ///
              $stu_chars, ///
              a(year period exam_code school id) vce(cluster exam_code#school)
          
              test ten_positive_wo_ext = ten_negative_wo_ext
              estadd scalar p_value_pos_neg = r(p)
              test ten_positive_wo_extXhomoge = ten_negative_wo_extXhomoge
              estadd scalar p_value_pos_neg_homoge = r(p)
          
          
              * Column 2: Add Sanction in Last Year
              eststo: reghdfe disqualified ten_positive_wo_ext ten_negative_wo_ext ///
              ten_positive_wo_extXhomoge ten_negative_wo_extXhomoge ///
              sanction_l1 $stu_chars, ///
              a(year period exam_code school id) vce(cluster exam_code#school)
          
              test ten_positive_wo_ext = ten_negative_wo_ext
              estadd scalar p_value_pos_neg = r(p)
              test ten_positive_wo_extXhomoge = ten_negative_wo_extXhomoge
              estadd scalar p_value_pos_neg_homoge = r(p)
          
          
              * Column 3: Add School Score
              eststo: reghdfe disqualified ten_positive_wo_ext ten_negative_wo_ext ///
              ten_positive_wo_extXhomoge ten_negative_wo_extXhomoge ///
              sanction_l1 school_score $stu_chars, ///
              a(year period exam_code school id) vce(cluster exam_code#school)
          
              * In this final column, add observations and students
              estadd scalar Observations = e(N)
              estadd scalar Students = e(dof_table)[5,1]
          
              test ten_positive_wo_ext = ten_negative_wo_ext
              estadd scalar p_value_pos_neg = r(p)
              test ten_positive_wo_extXhomoge = ten_negative_wo_extXhomoge
              estadd scalar p_value_pos_neg_homoge = r(p)
          
              
              local opt = cond(`i'==1, "replace", "append")
          
          
              esttab using "$path\Analysis\Old\22 June 25  - Itamar\table5_HHI_zipcodes.csv", ///
              se label b(%9.4f) se(%9.4f) star(* 0.10 ** 0.05 *** 0.01) ///
              noomitted nobaselevels nodepvar nomtitles noobs nocon ///
              scalars (p_value_pos_neg p_value_pos_neg_homoge Observations Students) sfmt(%9.4f %9.4f %10.0f %10.0f) ///
              title("`s'") `opt'
              
              local ++i
              
              restore
          }
          
          
          log close
          This is an example for one of the tables:

          Code:
                                  
                  Robust
          disqualified    Coefficient    std. err.    t    P>t    [95% conf.    interval]
                                  
          ten_positive_wo_ext    .0011496    .0002668    4.31    0.000    .0006266    .0016726
          ten_negative_wo_ext    .0032957    .0008655    3.81    0.000    .0015993    .0049921
          ten_positive_wo_extXhomoge    -.0046519    .0017303    -2.69    0.007    -.0080433    -.0012605
          ten_negative_wo_extXhomoge    -.0053198    .0055842    -0.95    0.341    -.0162651    .0056255
          sanction_l1    -.0017646    .0011763    -1.50    0.134    -.0040702    .000541
          school_score    -.0001294    9.25e-06    -13.99    0.000    -.0001475    -.0001113
          boy    0    (omitted)
          educ_f    .0001892    .0000689    2.75    0.006    .0000541    .0003243
          educ_m    -.0001658    .0000711    -2.33    0.020    -.0003051    -.0000265
          _cons    .0143579    .0008708    16.49    0.000    .0126511    .0160646
          Thanks again,

          Fitz

          Comment


          • #6
            This should give you one table, which you can then edit to insert empty columns between models and merge cells so that the titles span all models within a subsample.


            Code:
            *** Table 5: The Effect of Teacher Ethics and Homogeneity on Student Exam Dishonesty Across School Sectors  ***
            clear all
            set more off
            cap log close
            
            ********************************************************************************
            * Insert the correct path at the line below:
            global path "D:\School Ethics"
            ********************************************************************************
            
            use "$path\Data\ethics_data_98_02.dta", clear
            
            log using "$path\Analysis\Old\22 June 25  - Itamar\table5_HHI_zipcodes.txt", text replace
            ********************************************************************************
            
            gen ten_positive_wo_extXhomoge = ten_positive_wo_ext * hhi_school_zip
            label var ten_positive_wo_extXhomoge "Positive Ten-Point Difference X School HHI zipcodes Homogeneity Index"
            gen ten_negative_wo_extXhomoge = ten_negative_wo_ext * hhi_school_zip
            label var ten_negative_wo_extXhomoge "Negative Ten-Point Difference X School HHI zipcodes Homogeneity Index"
            
            global stu_chars boy educ_f educ_m
            global subsamples all jewish arab
            
            estimates clear
            foreach s in $subsamples{
                preserve
                di "`s'"
                keep if `s' == 1
                eststo clear
            
                * Column 1: Cohort and Exam Period FE, Gender and Parents Schooling, Exam Code FE, Student FE
                eststo: reghdfe disqualified ten_positive_wo_ext ten_negative_wo_ext ///
                ten_positive_wo_extXhomoge ten_negative_wo_extXhomoge ///
                $stu_chars, ///
                a(year period exam_code school id) vce(cluster exam_code#school)
            
                test ten_positive_wo_ext = ten_negative_wo_ext
                estadd scalar p_value_pos_neg = r(p)
                test ten_positive_wo_extXhomoge = ten_negative_wo_extXhomoge
                estadd scalar p_value_pos_neg_homoge = r(p)
            
            
                * Column 2: Add Sanction in Last Year
                eststo: reghdfe disqualified ten_positive_wo_ext ten_negative_wo_ext ///
                ten_positive_wo_extXhomoge ten_negative_wo_extXhomoge ///
                sanction_l1 $stu_chars, ///
                a(year period exam_code school id) vce(cluster exam_code#school)
            
                test ten_positive_wo_ext = ten_negative_wo_ext
                estadd scalar p_value_pos_neg = r(p)
                test ten_positive_wo_extXhomoge = ten_negative_wo_extXhomoge
                estadd scalar p_value_pos_neg_homoge = r(p)
            
            
                * Column 3: Add School Score
                eststo: reghdfe disqualified ten_positive_wo_ext ten_negative_wo_ext ///
                ten_positive_wo_extXhomoge ten_negative_wo_extXhomoge ///
                sanction_l1 school_score $stu_chars, ///
                a(year period exam_code school id) vce(cluster exam_code#school)
            
                * In this final column, add observations and students
                estadd scalar Observations = e(N)
                estadd scalar Students = e(dof_table)[5,1]
            
                test ten_positive_wo_ext = ten_negative_wo_ext
                estadd scalar p_value_pos_neg = r(p)
                test ten_positive_wo_extXhomoge = ten_negative_wo_extXhomoge
                estadd scalar p_value_pos_neg_homoge = r(p)
                
                restore
            }
            
            esttab est* using "$path\Analysis\Old\22 June 25  - Itamar\table5_HHI_zipcodes.csv", ///
                se label b(%9.4f) se(%9.4f) star(* 0.10 ** 0.05 *** 0.01) ///
                noomitted nobaselevels nodepvar nomtitles noobs nocon ///
                scalars (p_value_pos_neg p_value_pos_neg_homoge Observations Students) sfmt(%9.4f %9.4f %10.0f %10.0f) ///
                mtitles(" " "All" " " " " "Jewish" " " " " "Arab" " "   ) 
                
            
            log close

            Comment

            Working...
            X