Announcement

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

  • Creating a dataset with variables and their labels

    Hello!

    I have a large dataset with over 300 variables. Each variable has a label. My goal is to create a dataset with two columns: one containing the variables' name the other containing the respective variable label. What's the easiest way of achieving this?

    Thank you in advance for any help!

  • #2
    Assuming you have only one label language:

    Code:
    use your_dataset.dta
    describe , replace
    keep name varlab

    Comment


    • #3
      Code:
      sysuse auto, clear
      qui ds *
      frame create label str32 varname str80 label
      forval i= 1/`=wordcount("`r(varlist)'")'{
          frame post label ("`=word("`r(varlist)'", `i')'") ("`:var lab `=word("`r(varlist)'", `i')''")
      }
      frame change label
      list, sep(0)
      Res.:

      Code:
      . list, sep(0)
      
           +---------------------------------------+
           |      varname                    label |
           |---------------------------------------|
        1. |         make           Make and model |
        2. |        price                    Price |
        3. |          mpg            Mileage (mpg) |
        4. |        rep78       Repair record 1978 |
        5. |     headroom           Headroom (in.) |
        6. |        trunk    Trunk space (cu. ft.) |
        7. |       weight            Weight (lbs.) |
        8. |       length             Length (in.) |
        9. |         turn        Turn circle (ft.) |
       10. | displacement   Displacement (cu. in.) |
       11. |   gear_ratio               Gear ratio |
       12. |      foreign               Car origin |
           +---------------------------------------+

      Note: Crossed with #2, which is a more efficient approach.
      Last edited by Andrew Musau; 10 Apr 2024, 09:31.

      Comment


      • #4
        Thank you very much! It works!

        Comment

        Working...
        X