Announcement

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

  • New on SSC: -dataex-, a command to generate a properly formatted data example for Statalist

    Thanks to Kit Baum, a new command called dataex (with Nick Cox) is now available from SSC.

    With dataex, you can produce a data example that you can then copy and paste in a post on Statalist. Readers will be able to easily recreate your dataset and note the exact variable type and content. Even date/time formatting and value labels are carried over.

    dataex requires Stata version 9.2 or higher. To install, type

    Code:
    ssc install dataex
    Providing a good data example increases the likelihood of getting an answer. Make sure that you have read the FAQ before posting. Aim for a small example of your data, just enough to explain your data structure, variable types and names. If your data contains proprietary identifiers, you can easily anonymize them using the egen group() function. For example,

    Code:
    sysuse auto
    egen makeid = group(make)
    dataex makeid rep78 price foreign if rep78 == 5
    will produce the following output, which is copied as is from Stata's Results window

    Code:
    clear
    input float makeid int(rep78 price) byte foreign
    27 5 3984 0 
    55 5 4425 0 
    4 5 9690 1 
    24 5 4589 1 
    34 5 5799 1 
    66 5 3798 1 
    67 5 5899 1 
    68 5 3748 1 
    69 5 5719 1 
    71 5 5397 1 
    74 5 11995 1 
    end
    label def origin 0 Domestic, modify
    label def origin 1 Foreign, modify
    label values foreign origin
    The output already includes the correct tags to display the results in a code box.



  • #2
    While this is a useful addition to the toolbox, some thoughts:
    1. Statalist allows attachments and links to external resources
    2. Stata has a standard xmlsave/xmluse command to export/import data in the post-safe (plain text) format. The result can be posted into Statalist. It will save variable formats and other decor as well.

    Comment


    • #3
      Sergiy: Thanks for your appreciation. We seek to encourage people to show examples that can be seen and copied immediately.

      Comment


      • #4
        Robert, thank you for doing this! The attachments here have been very unreliable (I have tried), so I really welcome this addition (although it will get unwieldy pretty quickly with larger datasets, so this will be most useful for small ones).

        Comment


        • #5
          Philip: Thanks for the appreciation. dataex supports if and in to allow selection or sampling of large datasets. There is no intention that it be used to post anything more than fairly small data examples. More in the help as usual.

          Comment

          Working...
          X