Announcement

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

  • Exporting values labels into Excel

    Hello,

    I would like to have a data dictionary with my values ​​labels, is it possible to export them into an excel file?


    My base is like that :

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(ethnie genre pays)
    1 1 1
    2 2 2
    1 2 3
    1 1 4
    3 1 2
    2 1 1
    end
    label values ethnie ethnie
    label def ethnie 1 "Ethnie A", modify
    label def ethnie 2 "Ethnie B", modify
    label def ethnie 3 "Ethnie C", modify
    label values genre genre
    label def genre 1 "H", modify
    label def genre 2 "F", modify
    label values pays pays
    label def pays 1 "FR", modify
    label def pays 2 "BE", modify
    label def pays 3 "US", modify
    label def pays 4 "UK", modify
    And I would like to have a base like that :

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 variable float value str8 label
    "ethnie" 1 "Ethnie A"
    "ethnie" 2 "Ethnie B"
    "ethnie" 3 "Ethnie C"
    "genre"  1 "H"       
    "genre"  2 "F"       
    "pays"   1 "FR"      
    "pays"   2 "BE"      
    "pays"   3 "US"      
    "pays"   4 "UK"      
    end
    Is it possible ?

    Thanks !

  • #2
    Code:
    foreach v of varlist *{
        decode `v',gen(label`v')
        rename `v' value`v'
    }
    gen i = _n
    reshape long label value,i(i) j(variable) str
    label values value .
    collapse (first) value, by(variable label)
    
    . list
    
         +-----------------------------+
         | variable      label   value |
         |-----------------------------|
      1. |   ethnie   Ethnie A       1 |
      2. |   ethnie   Ethnie B       2 |
      3. |   ethnie   Ethnie C       3 |
      4. |    genre          F       2 |
      5. |    genre          H       1 |
         |-----------------------------|
      6. |     pays         BE       2 |
      7. |     pays         FR       1 |
      8. |     pays         UK       4 |
      9. |     pays         US       3 |
         +-----------------------------+
    Then export using -export excel- with whatever options you wish.
    Last edited by Ali Atia; 19 Apr 2022, 08:11.

    Comment


    • #3
      It's perfect ! Thanks you

      Comment


      • #4
        Code:
        uselabel , clear
        list

        Comment


        • #5
          Wow! Learn something new everyday.

          Comment

          Working...
          X