我有一個數據集應該被重新整形爲一個寬的格式。在多個層次上重新整形
數據目前很長,觀察結果爲給定學校中的每個人確定了「面積」。由於數據有兩層,因此傳統整形代碼出現問題:首先應該重新整形,以便每個觀察能夠唯一地識別一個人和一個學校(具有多個區域)。其次,我們最終應該對每個人(包含多個學校和多個區域)進行一次觀察。
下面是數據如何貌似現在一個例子:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str4 id str2 school_code str1 area
"a111" "1x" "a"
"a111" "1x" "b"
"a111" "1x" "c"
"a111" "1y" "a"
"a111" "1y" "b"
"a111" "1y" "c"
"x222" "1z" "d"
"x222" "1z" "e"
"x222" "1z" "f"
"x222" "1k" "g"
"x222" "1k" "h"
"x222" "1k" "i"
end
這裏是如何,我想數據集試探性的例子是:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str4 id str2(school_code_1 school_code_2) str1(school1_area1 school1_area2 school1_area3 school2_area1 school2_area2 school2_area3)
"a111" "1x" "1y" "a" "b" "c" "a" "b" "c"
"x222" "1z" "1k" "d" "e" "f" "g" "h" "i"
end