표시기 또는 더미 변수 20 개가 필요합니다. 먼저 forval
을 사용하여 1 (1) 20을 루프하는 것이 훨씬 쉽습니다.
forval j = 1/20 {
gen hou_as_`j' = 0
}
0
나는 단어가 공백으로 구분되어 단지 어떤 여기되고, 그것은 당신의 대답 변수의 말씀을 통해 루프 쉽게 생각 (20 개) 등의 변수를 초기화한다. 이 대부분 20 자에 있고, 그것은 조금 조잡하지만 빠른 될 가능성이 충분의 함께 그 넣어 귀하의 예제에 그것을 밖으로 시도하자
forval j = 1/20 {
forval k = 1/20 {
replace hou_as_`j' = 1 if word(hou_as, `k') == "`j'"
}
}
이동 :
clear
input str42 hou_as
"1 2 3 5 11 17 20"
"3 4 8 9 11 14 15 18 20"
"1 3 9 11"
end
forval j = 1/20 {
gen hou_as_`j' = 0
forval k = 1/20 {
replace hou_as_`j' = 1 if word(hou_as, `k') == "`j'"
}
}
것은 그냥 보여 그것은 일한 :
덧붙여
. list in 3
+----------------------------------------------------------------------------+
3. | hou_as | hou_as_1 | hou_as_2 | hou_as_3 | hou_as_4 | hou_as_5 | hou_as_6 |
| 1 3 9 11 | 1 | 0 | 1 | 0 | 0 | 0 |
|----------+----------+----------+----------+----------+----------+----------|
| hou_as_7 | hou_as_8 | hou_as_9 | hou_a~10 | hou_a~11 | hou_a~12 | hou_a~13 |
| 0 | 0 | 1 | 0 | 1 | 0 | 0 |
|----------+----------+----------+----------+----------+----------+----------|
| hou_a~14 | hou_a~15 | hou_a~16 | hou_a~17 | hou_a~18 | hou_a~19 | hou_a~20 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
+----------------------------------------------------------------------------+
, 당신의 라인
local P : subinstr local p "-" ""
유용한 것은 없습니다. 로컬 매크로 p
에는 정수 숫자 만있는 내용이 있으므로 제거 할 문장 부호가 전혀 없습니다.
은 this explanation 및
. search multiple responses, sj
Search of official help files, FAQs, Examples, SJs, and STBs
SJ-5-1 st0082 . . . . . . . . . . . . . . . Tabulation of multiple responses
(help _mrsvmat, mrgraph, mrtab if installed) . . . . . . . . B. Jann
Q1/05 SJ 5(1):92--122
introduces new commands for the computation of one- and
two-way tables of multiple responses
SJ-3-1 pr0008 Speaking Stata: On structure & shape: the case of mult. resp.
. . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox & U. Kohler
Q1/03 SJ 3(1):81--99 (no commands)
discussion of data manipulations for multiple response data
보기