Announcement

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

  • How do I export all observations of a string variable to an Excel file using putexcel?

    This thread

    http://www.statalist.org/forums/foru...le#post1332948

    is somewhat relevant, but code like this
    Code:
    putexcel set "results.xlsx", sheet("out") replace
    sysuse auto, clear
    putexcel A2 = make
    doesn't actually export the variable, despite what that thread says. It only exports the first observation. I could loop through each observation and export it, but surely there is an easier way to do this with putexcel, and looping through each observation means I have _N writes to the file, which is quite slow.

    Also, export excel is not an option in this case because I'm writing out variables of different data types from various datasets into the same sheet, and export excel doesn't allow for that level of fine-grained control.

    putexcel does allow for this level of control, unless there isn't a way to write the entire contents of a string variable (or even numeric variable) without jumping through a lot of hoops.

    Last edited by Michael Anbar; 15 Jul 2016, 07:56.

  • #2
    Originally posted by Michael Anbar View Post
    This thread

    http://www.statalist.org/forums/foru...le#post1332948

    is somewhat relevant, but code like this
    Code:
    putexcel set "results.xlsx", sheet("out") replace
    sysuse auto, clear
    putexcel A2 = make
    doesn't actually export the variable, despite what that thread says. It only exports the first observation. I could loop through each observation and export it, but surely there is an easier way to do this with putexcel, and looping through each observation means I have _N writes to the file, which is quite slow.

    Also, export excel is not an option in this case because I'm writing out variables of different data types from various datasets into the same sheet, and export excel doesn't allow for that level of fine-grained control.

    putexcel does allow for this level of control, unless there isn't a way to write the entire contents of a string variable (or even numeric variable) without jumping through a lot of hoops.
    Are the data types essential? Because export excel does have a cell(...) option? I have no idea what's causing the issue with putexcel - I'm getting the same problem trying it on my PC (only first observation is outputted).

    Comment


    • #3
      The cell and sheetmodify options do what I want. Thank you!

      Comment


      • #4
        It's worth noting that while the thread referenced in post #1 indeed suggests that putexcel output all the observations of a variable in one example, that suggestion is not supported by the documentation for putexcel at help putexcel and help putexcel advanced - both show that the syntax given above outputs the results of an expression, a single value.

        My take is that putexcel and export excel are designed for somewhat complementary purposes.

        Comment

        Working...
        X