Announcement

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

  • Export string variables

    Hi Statalist,

    I'm working with a large dataset and trying to export all string variables. I'm doing this because these responses require translation. What is the fastest/most efficient way to browse/keep/export only string variables?

  • #2
    Here is some technique to point you in the right direction.
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . ds, has(type string)
    make
    
    . list `r(varlist)' in 1/10
    
         +---------------+
         | make          |
         |---------------|
      1. | AMC Concord   |
      2. | AMC Pacer     |
      3. | AMC Spirit    |
      4. | Buick Century |
      5. | Buick Electra |
         |---------------|
      6. | Buick LeSabre |
      7. | Buick Opel    |
      8. | Buick Regal   |
      9. | Buick Riviera |
     10. | Buick Skylark |
         +---------------+
    
    .

    Comment


    • #3
      Code:
      ds, has(type string)
      keep `r(varlist)'
      will keep only the string variables. The usual commands for browsing and exporting then apply.

      If there are a lot of string variables, you may not want to see the long list of them that -ds- outputs. If so, just put -quitely- in front of -ds-.

      Note: This is the same solution as William Lisowski posted. Our posts crossed in transmission.

      Comment


      • #4
        Thanks, William. This is helpful for listing all string variables. Any idea how to tag string variables or keep only string variables in the dataset?

        Comment


        • #5
          Great - thanks, Clyde.

          Comment


          • #6
            The important point to both my post and Clyde's post is that after running the given ds command the macro r(varlist) contains a list of string variables. There was nothing magic about my then using it in a list command, nothing magic about Clyde's then using it in a keep command, and nothing preventing its use on an export command.

            I should have pointed out that the macro r(varlist) will be destroyed by the next command that returns results to r() so either the ds command should immediately precede the command that uses the variable list, or r(varlist) should be saved to another macro.
            Code:
            ds, has(type string)
            local strings `r(varlist)'
            ... other commands ...
            export excel `strings' using ...

            Comment

            Working...
            X