Announcement

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

  • Esttab

    Dear Stata Users

    I am running the following code:

    Code:
    tsset t
    eststo, title("Specification 1"): newey Kospi_rtr FindL1 KrtrL1, lag (4)
    eststo, title("Specification 2"): newey Kospi_rtr FinstL1 KrtrL1, lag (4)
    eststo, title("Specification 3"): newey Kospi_rtr FforL1 KrtrL1, lag (4)
    eststo, title("Specification 4"): newey Kospi_rtr FindL1 FinstL1 FforL1 KrtrL1, lag (4)
    
    esttab using "AlltradingdaysSpc_1to6.csv", append title ("All trading days") coeflabel(Kospi_rtr "MktRet" KrtrL1 "MktRetlag1" FinstL1 "NOFinstlag1" FindL1 "NOFindlag1" FforL1 "NOFforlag1") mtitle("Specification 1" "Specification 2" "Specification 3" "Specification 4") cells(b(fmt(a4)) t(fmt(2) par))
    I have the following questions:

    1. How do I modify a code so stars in *csv file are next to t-test, not next to the coefficients?
    2. How do I modify a code so that all coefficients are rounded to 4 decimal places?
    3. I would like to learn how to store estimates in an alternative way. I do not find esttab convinient. Results are stored in *csv file in a way difficult for further formating. All results are stored as text: ="-2.7589". What is the alternative way to export regression results to excel spreadsheet?

    Thank you.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(date Kospi_rtr KrtrL1) double(FindL1 FinstL1 FforL1) float t
    16072            .            .                       .                       .                       .  1
    16075  .0034521355            .  -.00011784640090361977 -.000014492068673607026   .00013303976064839485  2
    16076 -.0007618144  .0034521355  -.00001858190904077246   -.0001416343375096526   .00015651636168056407  3
    16077  .0044020107 -.0007618144  .000018082479620871834  -.00016446221751471266   .00013462336156651474  4
    16078  -.003502024  .0044020107  -.00006477076594818576 -3.3345260272982114e-07   .00006016959155763672  5
    16079   .025280854  -.003502024   .00005392315291704728  -.00019177899699457523   .00014004128167051442  6
    16082   .006735469   .025280854   .00005974674967805392   -.0002814979349148859    .0002048587521535676  7
    16083  -.002633596   .006735469   .00004558705455499578  -.00024026846992716876   .00018815614904580397  8
    16084   .001510634  -.002633596  5.0422022373254836e-06  -.00024286243549898894   .00023439698727461736  9
    16085  -.004660404   .001510634  -.00005916039672485067   -.0001394851531256149   .00020226736243540263 10
    16086   .002659278  -.004660404  -.00002696289054936368  -.00018635229934024485   .00021394409638796945 11
    16089   .010396816   .002659278  -.00001855893899501892  -.00010975959939948518    .0001450185866311689 12
    16090   .005474417   .010396816  -.00003531531244060233  1.2933848632624244e-06   6.398041111203486e-06 13
    16096   .008986297   .005474417  .000051049563318311274  -.00025103944510139947   .00018963230428067942 14
    16097  -.006826825   .008986297   .00004450510832651873    -.000276131753983601   .00022765945922570803 15
    16098 -.0040353634  -.006826825 -.000026097850002825813   -.0001297627364251843   .00015474188742275192 16
    16099  -.007212835 -.0040353634  -7.198678220123213e-07   -.0002029224247545971   .00016799711247339746 17
    16100  -.005960808  -.007212835   .00021304781149620106  -.00016525868962050805 -.000032531174397505135 18
    16103   .007372697  -.005960808   .00019594228901980684   -.0002668573913719077   .00007241820787580663 19
    16104  -.017620752   .007372697  .000013253134273047228  -.00006864797096860753  .000047788760478552585 20
    end
    format %tdNN/DD/CCYY date


  • #2
    You didn't get a quick answer. Part of the problem may be that some don't see changing where you put stars as worth taking our time to help you.

    There are a number of routines that make tables - outreg, outreg2, etc. One of them might do what you want.

    Comment


    • #3
      Thank you Phil.

      I thought a combination of clear question + data example would not consume a lot of time for the expert to show how to amend a code. My question may seem cheap on the surface of it but for the one who runs 100s regressions and exports results (in the text format) to excel knowing how to put a star along t-stat makes significant difference.

      I have checked outreg and did not find it to be different from esttab for the code I am running.

      Comment


      • #4
        Dear Olena

        outreg2 is not the same as outreg. You can certainly specify which statistics you want and the number of decimal places for each statistic. There are several options for controlling asterisks, but I am not familiar with them. It might do what you want.

        Comment


        • #5
          Hi Olena,

          Originally posted by Olena Onishchenko View Post
          Dear Stata Users
          [...]
          I have the following questions:

          1. How do I modify a code so stars in *csv file are next to t-test, not next to the coefficients?
          2. How do I modify a code so that all coefficients are rounded to 4 decimal places?
          3. I would like to learn how to store estimates in an alternative way. I do not find esttab convinient. Results are stored in *csv file in a way difficult for further formating. All results are stored as text: ="-2.7589". What is the alternative way to export regression results to excel spreadsheet?
          [...]
          the short answer to all three of your questions is: please read through esttab's very detailed help file, or the online documentation (which is also directly hyperlinked in the help file). Both provide a detailed description of the available options, and an excessive amount of examples. They include the solution to your problems. This statement may also be valid to achieve the same result with outreg and/or outreg2, but I somewhen chose to go with esttab and are not very familiar with both.

          In your example, you mix up several options of esttab with options of the underlying, even more powerful but excessively detailed estout. I think this might be the source of your confusion.

          My longer answers:

          Regarding 1.: instead of "cells(b(fmt(a4)) t(fmt(2) par))", you may want to write "b(a4) t(2) parentheses staraux". cells() is an option from estout. The convenience option for esttab making it display significance stars with the t-statistics is "staraux". To output the t-statistics in parentheses, use "parentheses".

          Regarding 2.: instead of "b(fmt(a4))", you want to write "b(fmt(4))" inside the cells()-option. You inserted an extra "a" in the format; as the help files for estout and esttab explain, an a#-format will print the values with a variable width to display all values with a minimal precision of 4 non-zero decimal places. This works perfectly in your example, but does not round to exactly 4 decimal places (as you expect). It is the format 4 that you want to use instead. Again, cells() is an option to estout, not esttab. The convenience options for what you want to see are "b(4) t(2)".

          Regarding 3.: I can't help you in finding esttab inconvenient. From my personal experience, it is the most powerful and most capable tool for automated export of tables (not only regression, but all other kinds of tables, like descriptive statistics and the like) to a document. But that's my personal opinion, and may be biased by (a) my kind of workflow (automate as much as possible from within Stata, so that the results don't have to be touched afterwards) or tools (mostly LaTeX). Anyways, the answer to the formatting question of the output CSV is in the help file of esttab: add the option plain to your command, and the Excel-stable formatting is not performed when writing the CSV.

          Here's my version of your code that, I guess, solves your problems; I put in bold font everything that I had to change:
          Code:
          clear
          input float(date Kospi_rtr KrtrL1) double(FindL1 FinstL1 FforL1) float t
          16072            .            .                       .                       .                       .  1
          16075  .0034521355            .  -.00011784640090361977 -.000014492068673607026   .00013303976064839485  2
          16076 -.0007618144  .0034521355  -.00001858190904077246   -.0001416343375096526   .00015651636168056407  3
          16077  .0044020107 -.0007618144  .000018082479620871834  -.00016446221751471266   .00013462336156651474  4
          16078  -.003502024  .0044020107  -.00006477076594818576 -3.3345260272982114e-07   .00006016959155763672  5
          16079   .025280854  -.003502024   .00005392315291704728  -.00019177899699457523   .00014004128167051442  6
          16082   .006735469   .025280854   .00005974674967805392   -.0002814979349148859    .0002048587521535676  7
          16083  -.002633596   .006735469   .00004558705455499578  -.00024026846992716876   .00018815614904580397  8
          16084   .001510634  -.002633596  5.0422022373254836e-06  -.00024286243549898894   .00023439698727461736  9
          16085  -.004660404   .001510634  -.00005916039672485067   -.0001394851531256149   .00020226736243540263 10
          16086   .002659278  -.004660404  -.00002696289054936368  -.00018635229934024485   .00021394409638796945 11
          16089   .010396816   .002659278  -.00001855893899501892  -.00010975959939948518    .0001450185866311689 12
          16090   .005474417   .010396816  -.00003531531244060233  1.2933848632624244e-06   6.398041111203486e-06 13
          16096   .008986297   .005474417  .000051049563318311274  -.00025103944510139947   .00018963230428067942 14
          16097  -.006826825   .008986297   .00004450510832651873    -.000276131753983601   .00022765945922570803 15
          16098 -.0040353634  -.006826825 -.000026097850002825813   -.0001297627364251843   .00015474188742275192 16
          16099  -.007212835 -.0040353634  -7.198678220123213e-07   -.0002029224247545971   .00016799711247339746 17
          16100  -.005960808  -.007212835   .00021304781149620106  -.00016525868962050805 -.000032531174397505135 18
          16103   .007372697  -.005960808   .00019594228901980684   -.0002668573913719077   .00007241820787580663 19
          16104  -.017620752   .007372697  .000013253134273047228  -.00006864797096860753  .000047788760478552585 20
          end
          format %tdNN/DD/CCYY date
          
          tsset t
          eststo, title("Specification 1"): newey Kospi_rtr FindL1 KrtrL1, lag (4)
          eststo, title("Specification 2"): newey Kospi_rtr FinstL1 KrtrL1, lag (4)
          eststo, title("Specification 3"): newey Kospi_rtr FforL1 KrtrL1, lag (4)
          eststo, title("Specification 4"): newey Kospi_rtr FindL1 FinstL1 FforL1 KrtrL1, lag (4)
          
          esttab using "AlltradingdaysSpc_1to6.csv", append title("All trading days") coeflabel(Kospi_rtr "MktRet" KrtrL1 "MktRetlag1" FinstL1 "NOFinstlag1" FindL1 "NOFindlag1" FforL1 "NOFforlag1") mtitle("Specification 1" "Specification 2" "Specification 3" "Specification 4") b(4) t(2) parentheses staraux csv plain
          Regards
          Bela
          Last edited by Daniel Bela; 08 Feb 2018, 06:58.

          Comment


          • #6
            Daniel

            Thank you for detailed answer. It is very helpful.

            Regards,
            Olena

            Comment


            • #7
              So I end up using outreg2 to export regression results to Excel. To answer your questions above using outreg2:

              I have the following questions:

              1. How do I modify a code so stars in *csv file are next to t-test, not next to the coefficients?
              2. How do I modify a code so that all coefficients are rounded to 4 decimal places?
              3. I would like to learn how to store estimates in an alternative way. I do not find esttab convenient. Results are stored in *csv file in a way difficult for further formatting. All results are stored as text: ="-2.7589". What is the alternative way to export regression results to excel spreadsheet?
              1. To put asterisks next to T-Stat rather than coef, asterisk(tstat)
              2. To set so coefficients are rounded to 4 decimal places? bdec(4)
                1. If you also want t-stats or p-values to 4 decimal places, tdec(4)
              3. To export to Excel (as opposed to .txt or .csv files), just specify, "excel"
              So the overall syntax is:
              Code:
              * Run regression #1
              reg dv rhs_vars if sample==1
              outreg2 using "AlltradingdaysSpc_1to6", excel tstat bdec(4) tdec(4) asterisk(tstat) bracket addstat(F test: , e(F)) adec(3) ctitle("Spec 1") replace
              * Bracket means put t-stat in bracket, not parentheses
              * Addstat means add statistic, adec(3) means report the added statistic with 3-decimal places
              
              * Run regression  #2
              reg dv rhs_vars if sample==1
              outreg2 using "AlltradingdaysSpc_1to6", excel tstat bdec(4) tdec(4) asterisk(tstat) bracket addstat(F test: , e(F)) adec(3) ctitle("Spec 2") append
              
              ...and so on
              
              NOTE: In practice I store much of this in local macros (so I only need to edit in one place)
              It also makes it *much* easier to read
              
              * Setting local macros
              local rhsvars "var1 var2 var3 firm_size ln_sales tobin_q firm_age"  // the control variables I include in every regression
              local outreg_file "AlltradingdaysSpc_1to6"
              local do_file "Path for do file"
              local outreg_line1 "excel tstat bdec(4) tdec(4) asterisk(tstat)  bracket addstat(F test: , e(F)) adec(3)"
              
              * Run regression #1
              reg dv `rhsvars' if sample==1
              outreg2 using `outreg_file', `outreg_line1' ctitle("Specification 1") ///
              addnote("", do file is `do_file', "Run on $S_DATE", Log file is `log_file', Using data from $S_FN) replace
              * This adds all this info to bottom of Excel sheet with regressions, $S_FN is the filename of the .dta file used
              * It only needs to be put in after the first regression
              
              * Run regression #2
              reg dv  new_var `rhsvars' if sample==1  
              outreg2 using `outreg_file', `outreg_line1' ctitle("Specification 2") append
              
              * Run regression #3
              reg dv  new_var2 `rhsvars' if sample==1  
              outreg2 using `outreg_file', `outreg_line1' ctitle("Specification 3") append
              
              ...and so on.

              Comment

              Working...
              X