Announcement

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

  • Exporting strate output using putexcel

    I am conducting survival data analysis using 'strate 'to calculate event rates. Since I have to calculate event rates for many groups, I would like to automatically export my strate results to an excel file. However, I cannot find a way for the putexcel command to read my strate output.

    I have used to following code to calculate event rates:

    stset persontime, failure(event==1)
    stdescribe
    strate, per(1000)

    STATA returns the following output:
    +-----------------------------------------+
    | D Y Rate Lower Upper |
    |-----------------------------------------|
    | 346 7.4678 46.332 41.699 51.481 |
    +-----------------------------------------+

    When using a code for putexcel that was previously suggested (https://www.statalist.org/forums/for...tes-into-excel), the excel file remained empty:

    putexcel set resultfile
    stset persontime, failure(event==1)
    strate, per(1000)
    putexcel A1=(r(Rate)) B1=(r(Lower)) C1=(r(Upper))

    I have seen tips telling to put my output in a matrix format, which I tried using the following code:
    matrix list r(table)
    However, STATA returned error code r(111): matrix r(table) not found

    If anyone could help me identify where and/or how to fix my code, it would be much appreciated!


    P.S. I saw a response recommending the use of the asdoc command. Although this worked fine, I prefer to export selected data to excel

  • #2
    You have the option to save the output as a dataset. So do that and export to Excel using export excel.

    Code:
    strate, per(1000) output(myfile, replace)
    preserve
    use myfile, clear
    export excel myfile, firstrow(varlab) replace
    restore

    Comment


    • #3
      If you are interested, asdocx can now export to Excel as well. To export from the strate command, here is a working example
      Code:
      webuse diet
      stset dox, origin(time doe) id(id) scale(365.25) fail(fail==1 3 13)
      stsplit ageband, at(40(10)70) after(time=dob) trim
      strate ageband, per(1000) output(test)
      use text, clear
      asdocx list, save(myfile.xlsx) replace
      Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	52.8 KB
ID:	1604691


      It produces the attached file.

      Attached Files
      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


      • #4
        Andrew Musau
        Many thanks! I managed to copy my results into a dta file and export them to excel However, I still struggle to add the results of a following event rate analysis to the same excel file, in a row below the original results. Is there a function to add results to an existing file, starting from a specified left-upper cell (or a command that resembles the 'append' command for asdoc)?

        Comment


        • #5
          You have a number of possibilities, including using the -cell()- option of export excel to specify where to place the table in an existing file

          cell(start) - start (upper-left) cell in Excel to begin saving to
          or you could put the estimates in a matrix and proceed with your putexcel sequence in #1:

          Code:
          strate, per(1000) output(myfile, replace)
          preserve
          use myfile, clear
          mkmat *, mat(results)
          restore
          mat list results

          Comment


          • #6
            Thank you very much! using the cell() option, together with the sheetmodify option, I have managed to put the different outputs in an excel file together

            Comment

            Working...
            X