Announcement

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

  • Reshaping a dataset with a "list" format i.e. each variable lists a group of different individuals

    Dear members of the forum,

    I am trying to reshape a dataset in the appropriate format. I work at the city/individual. Suppose I have this dataset:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str3(city1 city2 city3)
    "xxx" "yyy" "zzz"
    "aaa" "bbb" "ccc"
    end
    I would simply like to turn it that way:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str5 city str3 individual
    "city1" "xxx"
    "city1" "aaa"
    "city2" "yyy"
    "city2" "bbb"
    "city3" "zzz"
    "city3" "ccc"
    end
    aaa, bbb, ccc, xxx, yyy, zzz are all individuals. With this second dataset, there is one observation per city/individual whereas in my current dataset I cannot work the way I want to because one observation denotes several individuals across different cities.

    Is there a simple way to deal with this problem?

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str3(city1 city2 city3)
    "xxx" "yyy" "zzz"
    "aaa" "bbb" "ccc"
    end
    
    rename * data* 
    gen id = _n 
    
    reshape long data, i(id) j(which) string 
    
    list

    Comment

    Working...
    X