Long → Wide
예시를 위해서 bplong을 사용하였다.
sysuse bplong
br
이 테이블을 가로로 Wide한 형태로 만들 것이다. 현재는 혈압이 세로로 Before, After로 표시되어 있지만, bp를 가로로 전 후로 나타낼 것이다.
reshape wide bp, i(patient) j(when)
br
. reshape wide bp, i(patient) j(when)
(j = 1 2)
Data Long -> Wide
------------------------------------------------------------------------
> -----
Number of observations 240 -> 120
Number of variables 5 -> 5
j variable (2 values) when -> (dropped)
xij variables:
bp -> bp1 bp2
------------------------------------------------------------------------
Before이 bp1으로, After이 bp2로 확인된 것을 확인할 수 있다.
Wide → Long
예시를 위해 bpwide를 사용하였다.
sysuse bpwide, clear
br
가로로 표현되어 있는 bp_before, bp_after를 세로로 표현할 것이다.
그렇게 하기 전에 bp_before을 bp_1, be_after를 bp_2로 바꾸어주어야 한다.
rename bp_before bp1
rename bp_after bp2
이제 reshape을 사용할 수 있다.
reshape long bp, i(patient) j(idx)
br
rehape long 세로로 표현하고 싶은 변수 숫자 뗀 이름, i(아이디) j(새로운 index 이름)
. reshape long bp, i(patient) j(idx)
(j = 1 2)
Data Wide -> Long
------------------------------------------------------------------------
> -----
Number of observations 120 -> 240
Number of variables 5 -> 5
j variable (2 values) -> idx
xij variables:
bp1 bp2 -> bp
------------------------------------------------------------------------
(만약에 이름을 bp3, bp4로 변경했다면 idx는 1,2가 아닌 3,4가 될 것이다.)
'STATA' 카테고리의 다른 글
08. [STATA] for statement 한꺼번에 확인하기 (0) | 2021.08.17 |
---|---|
07. [STATA] 기초 통계 chi-squared, t-test (0) | 2021.08.06 |
05. [STATA] 두 개 테이블 합치기 (0) | 2021.08.03 |
04. [STATA] 변수 생성, 수정, missing value, recoding (0) | 2021.08.02 |
03. [STATA] 변수 확인하기 (0) | 2021.08.01 |
댓글