Announcement

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

  • Restrict decimal places in -tabstat results exported to Excel via -putexcel

    I want to export a lot of descriptive statistics produced via -tabstat to Excel via -putexcel. I am working on a remote server which is not too happy about exporting results containing 16 digits to my PC. Therefore I need to restrict the number of decimals which are in the resulting excelfile. It seems, that using the format() option in -tabstat only restricts the decimal places in the Stata output, but not in the results which are exported to Excel:

    Code:
    putexcel set test, modify
    sysuse auto
    tabstat weight gear_ratio turn, by(rep78) save format(%9.1f)
    forval x = 1/5{
        putexcel b`x'=matrix(r(Stat`x'))
    }
    How can I restric the number of decimals in the Excel results? The remote server won't let me modify anything in Excel using Excel, i.e., I need to do it all via the Stata commands. In my real data I have 43 variables, 4 descriptive statistics for 5 subgroups, so I am not sure that storing the results in new variables (43*4*5=860) with numbers rounded to 3 decimal places are effecient.
    Last edited by Emil Alnor; 07 Mar 2023, 01:29. Reason: spelling

  • #2
    You could use the new table command and export to Word, and than move that to Excel (exporting directly to Excel still maintains all digit, but with Word you first loose it.)

    Code:
    sysuse auto, clear
    table (rep78) (var), stat(mean weight gear_ratio turn) nformat(%6.0f weight)
    collect style cell var[weight], nformat(%6.0f)
    collect style cell var[gear_ratio], nformat(%6.2f)
    collect style cell var[turn], nformat(%6.1f)
    collect preview
    
    collect export c:\temp\foo.docx, replace
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks Maarten, using the table command instead was the solution. Only problem is that it is very slowly in exporting results, compared to -tabstat.

      Comment

      Working...
      X