Announcement

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

  • Exporting variable names and corresponding labels

    Hey,

    Is there a way in STATA to export variable names and corresponding labels? I tried a few things with the "Export" and putexcel options and am not getting the right output.

    Any help would be greatly appreciated.

    Many thanks!

    Claudia

  • #2
    You could put that information in extra variables in your dataset and then export those variables.

    Code:
    sysuse auto, clear
    unab all : * 
    gen vname = ""
    gen vlabel = ""
    local i = 0
    quietly foreach v of local all {
        local ++i 
        replace vname = "`v'" in `i'
        replace vlabel = "`: var label `v''" in `i'
    }
    l vname vlabel in 1/`i'
    Also, search for Roger Newson's descsave

    http://www.statalist.org/forums/help#spelling

    Comment


    • #3
      There's also the often overlooked replace option for describe:

      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . describe, replace
      
      . list
      
           +---------------------------------------------------------------------------------------+
           | position           name    type   isnume~c   format   vallab                   varlab |
           |---------------------------------------------------------------------------------------|
        1. |        1           make   str18          0    %-18s                    Make and Model |
        2. |        2          price     int          1   %8.0gc                             Price |
        3. |        3            mpg     int          1    %8.0g                     Mileage (mpg) |
        4. |        4          rep78     int          1    %8.0g                Repair Record 1978 |
        5. |        5       headroom   float          1    %6.1f                    Headroom (in.) |
           |---------------------------------------------------------------------------------------|
        6. |        6          trunk     int          1    %8.0g             Trunk space (cu. ft.) |
        7. |        7         weight     int          1   %8.0gc                     Weight (lbs.) |
        8. |        8         length     int          1    %8.0g                      Length (in.) |
        9. |        9           turn     int          1    %8.0g                 Turn Circle (ft.) |
       10. |       10   displacement     int          1    %8.0g            Displacement (cu. in.) |
           |---------------------------------------------------------------------------------------|
       11. |       11     gear_ratio   float          1    %6.2f                        Gear Ratio |
       12. |       12        foreign    byte          1    %8.0g   origin                 Car type |
           +---------------------------------------------------------------------------------------+

      Comment


      • #4
        Thanks so much Nick and Robert!

        It worked.

        Have a good day.

        Claudia

        Comment

        Working...
        X