티스토리 뷰
Stata 에서 분석한 결과물을 Word 파일에 그대로 담을 수 있는 방법이 있습니다.
명령어 putdocx 를 사용하면 비교적 편리하게 생성할 수 있습니다.
실제 사용해보니, 문장을 만들기가 좀 번거롭고, 요약통계량 등의 표를 워드로 내보내기가 쉽지는 않았습니다.
테이블을 자료의 형태로 생성해서 그걸 내보내거나, 메트릭스의 형태로 내보내야 하는데
추가적인 작업을 해야되서 바쁜 연구자들은 매우 귀찮아 할 것 같습니다.
나중에 outreg2 같은 결과물들도 쉽게 포함할 수 있으면 좋겠다.
또 한 가지 난점은, 워드는 괜찮은데 아래아에서 워드 파일을 읽을 때 잘 읽혀지지 않았습니다.
한워드에서는 잘 작동하긴 합니다. 한글에서 워드 파일 읽어들이는 기능이 개선이 되면,
Stata -> 워드 -> 아래아로 이어지는 문서편집 과정이 좀 쉬워질 것 같습니다.
sysuse auto, clear
putdocx begin, pagesize(A4)
* 일반적인 문장
putdocx paragraph
putdocx text ("1978년도의 자동차에 대한 자료입니다."), bold
putdocx paragraph
putdocx text ("1978년도 미국에서 팔린 자동차의 제조사와 모형, 그리고 자동차의 특성에 대한 자료입니다."), linebreak
putdocx text ("예를 들면, 1978년도 자동차의 ")
putdocx text ("평균가격"), bold
putdocx text ("은 다음과 같습니다."),
putdocx paragraph, halign(center)
qui sum price
local sum : display %9.1fc `r(mean)'
putdocx text ("가격평균 =`sum'")
* 그래프 그리기
putdocx paragraph
putdocx text ("이렇게 그림도 넣을 수가 있습니다."), linebreak(2)
putdocx table t1 = (1,1), border(all, nil)
putdocx table t1(1,1) = ("<표 1> 국산 여부 별 가격 분포"), halign(center)
byhist price, by(foreign) tw(scheme(538) )
graph export hist.png, replace
putdocx table t1(1,1) = image(hist.png), append
* 추정결과
putdocx pagebreak
putdocx paragraph
putdocx text ("회귀분석 테이블도 넣을 수가 있습니다.")
quietly regress price mpg
estimates store model1
quietly regress price mpg i.foreign
estimates store model2
estimates table model1 model2, b(%10.3f) se(%10.3f) stats(N r2 r2_a) varlabel
putdocx table tbl1 = etable
* 요약표 기록
putdocx pagebreak
preserve
statsby total=r(N) average=r(mean) max=r(max) min=r(min), by(foreign): summarize price
putdocx table tbl2 = data("foreign total average max min"), varnames border(start, nil) border(end, nil)
putdocx table tbl2(., 1), halign(center)
putdocx table tbl2(1, 1/5), halign(center)
putdocx table tbl2(2/3, 2/5), halign(right)
restore
putdocx save example.docx, replace
putdocx clear
이와 같이 하면 아래와 같은 워드 문서를 자동화 하여 생산할 수 있다.