Announcement

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

  • EZ way to output a table generated from List?

    Hello SL,

    Despite a lot of searching and tinkering, I can't figure out how to output a table I have generated via -list- command into a database file. I should note that I am using Stata12 so I don't have access to -putexcel-

    Starting with a list of countries by change in poverty rate (list country change_pov in 1/5) I'd like to output the results of what's generated in the Results window:

    +--------------------------------------+
    | country chang~190 |
    |--------------------------------------|
    1. | Swaziland -33.55 |
    2. | Mali -28.97 |
    3. | Central African Republic -28.54 |
    4. | Sierra Leone -25.05 |
    5. | Uganda -19.465 |

    Yes, I can cut-and-paste this, but for larger lists it's time consuming (and inelegant!). How do I save the results of the List command as a CSV or Excel file?

    Thanks!

    -nick
    Last edited by Nick Cain; 01 Aug 2016, 16:49.

  • #2
    I'm not quite sure what the importance of the list command is: it just selects and displays two variables from five observations of the data in memory.

    It seems to me you should be able to accomplish what you need with export excel or the more flexible putexcel.

    Comment


    • #3
      William Lisowski Hi, I only have Stata 12 so I can't use -putexcel- and the Export > Excel function does not return the output of my results window, which contains a list of 20 countries ordered by a variable. I guess I can use -egen- to create a ranking and then output to Excel, but that seems unduly complicated. I apologize if there's something obvious I am overlooking, but despite a lot of research, I haven't found a package or function...

      Comment


      • #4
        ... of my results window, which contains a list of 20 countries ordered by a variable
        Not exactly - it contains a list of 5 (in your example, 20 in your real situation) observations of the variables country and change_pov, preceded by the observation number. The ordering of the observations was produced by a previous sort, or some other means.

        Since I don't have access to the Stata 12 documentation (I started with Stata 13) I can only hope the following will point you in the right direction given the capabilities of Stata 12.
        Code:
        generate rank = _n
        export excel rank country change_pov in 1/5 using yourfile.xlsx

        Comment


        • #5
          William Lisowski Yes, I just included a snippet of the actual output. Thanks for your thoughts. I did it manually in Excel.

          Comment


          • #6
            Since I wasn't able to help you with your Stata problem, let me make a suggestion that may assist you with your Statalist problem.

            Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post, looking especially at sections 9-12 on how to best pose your question. Along with discussing what you have tried, and why you feel it has not worked, please read FAQ #12 and use dataex and CODE delimiters when posting to Statalist. For example, the following:

            [code]
            . sysuse auto, clear
            (1978 Automobile Data)

            . describe make price

            storage display value
            variable name type format label variable label
            -----------------------------------------------------------------
            make str18 %-18s Make and Model
            price int %8.0gc Price
            [/code]

            will be presented in the post as the following:
            Code:
            . sysuse auto, clear
            (1978 Automobile Data)
            
            . describe make price
            
                          storage   display    value
            variable name   type    format     label      variable label
            -----------------------------------------------------------------
            make            str18   %-18s                 Make and Model
            price           int     %8.0gc                Price

            Comment


            • #7
              In addition to William's excellent advice, just use outsheet; that's what it is for.

              EZ: Just say no to such expressions.
              Last edited by Nick Cox; 02 Aug 2016, 04:13.

              Comment


              • #8
                Nick Cox I agree that outsheet will work for Nick Cain, since he's using Stata version 12. But as a general principle, in versions 13 and above it's not as easy to find out about - it's not documented in [R] for example, and help outsheet tells you it's been superseded by import delimited (more accurately, export delimited).

                But more to the poiint, in post #3 he suggests that export delimited, and thus presumably outsheet, does not meet his needs, but does not tell us how it fails, other than that "it does not return the results of his results window" (an odd thing to expect of any Stata command). In post #6 I show code that suggests it can output the first 20 rows of his dataset, giving an observation number and 2 variables, and preceded by column headings, as his list command produced in the results window, but having "done it manually in Excel" he apparently is no longer interested, as he was in post #1, about learning a less inelegant approach.

                Comment


                • #9
                  William: No disagreement with anything you say.

                  I was just focusing on exporting a .csv (the expression "Excel file" is too vague).
                  Last edited by Nick Cox; 02 Aug 2016, 06:04.

                  Comment

                  Working...
                  X