Announcement

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

  • New version of -dataex- on SSC

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

    dataex produces a data example in Stata's Results window that can be copied and pasted in a post on Statalist or shared elsewhere (e.g. in a query to Stata Tech Support). 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.

    To update to the new version, type in Stata's Command window:

    Code:
    adoupdate dataex, update
    To install dataex for the first time, type

    Code:
    ssc install dataex
    The new version simplifies value label definitions when multiple variables use the same value labels (thanks to Ana Maria Martinez and Joe Canner for noticing the issue in this post). The new version also checks that floating point values can be read back to within an epsilon (in proportion) of the original (1e-7 for a float, 1e-16 for a double). This ensures that all significant digits of very long identifiers are fully displayed. Finally, the dataex now aligns data in columns which makes it easier to visualize the data in a post.

    Here's a quick example that lists the first 5 observations of Stata's standard auto dataset. The following shows what appears in Stata's Results window:

    Code:
    . clear
    
    . sysuse auto
    (1978 Automobile Data)
    
    . dataex in 1/5
    
    ----------------------- copy starting from the next line -----------------------
    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str18 make int(price mpg rep78) float headroom int(trunk weight length turn displacement) float gear_ratio byte foreign
    "AMC Concord"   4099 22 3 2.5 11 2930 186 40 121 3.58 0
    "AMC Pacer"     4749 17 3   3 11 3350 173 40 258 2.53 0
    "AMC Spirit"    3799 22 .   3 12 2640 168 35 121 3.08 0
    "Buick Century" 4816 20 3 4.5 16 3250 196 40 196 2.93 0
    "Buick Electra" 7827 15 4   4 20 4080 222 43 350 2.41 0
    end
    label values foreign origin
    label def origin 0 "Domestic", modify
    [/CODE]
    ------------------ copy up to and including the previous line ------------------
    
    
    .
    To use the data example in a Stata post, a user needs to copy from Stata's Results window everything that's in between the "---- copy ---" instruction lines (this includes the [CODE] and [/CODE] formatting instructions. When pasted in this post, the example appears as

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str18 make int(price mpg rep78) float headroom int(trunk weight length turn displacement) float gear_ratio byte foreign
    "AMC Concord"   4099 22 3 2.5 11 2930 186 40 121 3.58 0
    "AMC Pacer"     4749 17 3   3 11 3350 173 40 258 2.53 0
    "AMC Spirit"    3799 22 .   3 12 2640 168 35 121 3.08 0
    "Buick Century" 4816 20 3 4.5 16 3250 196 40 196 2.93 0
    "Buick Electra" 7827 15 4   4 20 4080 222 43 350 2.41 0
    end
    label values foreign origin
    label def origin 0 "Domestic", modify
    Last edited by Robert Picard; 16 Sep 2015, 10:45.

  • #2
    Thanks to Kit Baum, a new version of dataex is now available on SSC.

    The new version implements two strategies to prevent bewilderment when a (new) Stata user unintentionally generates a large data dump in the Results window. There's now a limit of 100 observations listed unless the count(#) option is used to explicitly request more (or less). Also, dataex is able to recover if the Break key is pressed. This will be particularly useful if the user is working with set more on and the Break key is pressed to stop the output. Many thanks to William Lisowski for raising this issue and for his thoughtful suggestions on how to deal with it and for taking time to road test the new version.

    To install the new version, type in Stata's Command window:

    Code:
    ssc install dataex, replace

    Comment


    • #3
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long CITY1 float PFPERMINS
       9 0
      85 0
      85 0
      25 0
      70 0
      end
      label values CITY1 CITY1
      label def CITY1 9 "BATON ROUGE", modify
      label def CITY1 25 "DETROIT", modify
      label def CITY1 70 "ROCHESTER", modify
      label def CITY1 85 "SYRACUSE", modify
      This is what my data looks like, I have dummy variables for cities and numeric values for another variable, PFPERMINS, and would also like to have the actual city name appear rather than the number of the variable "BATON ROUGE" instead of "9"

      Comment


      • #4
        No, you are completely missing the point of -dataex-. The output of -dataex- is not intended to be read by human eyes. It is intended to be copied and pasted into a do-file and run as Stata code to re-generate the data set that gave rise to it. For that purpose it is absolutely critical that your CITY1 variable be represented numerically and then have the value labels assigned, as the code shown in your -dataex- does. The point of -dataex- is to represent your data exactly as it is in Stata, with no ambiguity between value-labeled numeric variables and string variables.

        Comment

        Working...
        X