내 데이터 (예 : 연령, 성별)에서 신뢰 구간을 사용하여 그룹 집합의 요약 통계를 계산하고 싶습니다. 그 목적을 위해 필자는 데이터의 모든 행에 대한 포아송 분포에서 값을 그린 몬테카를로 시뮬레이션을 사용하고 행을 요약하여 요약합니다. 시뮬레이션의 결과가 하나의 값 (rclass의 리턴 스칼라 사용)이지만, 하나 이상의 결과 (eclass의 ereturn 행렬 사용)를 시뮬레이트하자마자 작동하지 않습니다 (아래의 Stata 코드를 참조하십시오).). 오류 메시지가 나타납니다 : "식의 형식 불일치 오류 : e (A)". 더 복잡한 루프가 없으면 전체 벡터 또는 심지어 결과 행렬을 어떻게 시뮬레이션 할 수 있습니까?Stata의 전체 행렬에 대한 몬테카를로 시뮬레이션
감사합니다. 프레드
program bootPGW, eclass
use "C:\Users\649007\Desktop\Demetriq_PWG_edu.dta", replace
gen id=_n
sort id
gen N=_N
by id: gen DL2=floor(rpoisson(calung))
by id:gen D02=floor(rpoisson(D0))
by id:gen Dsmoking=floor(rpoisson(smoking))
by id:gen ML2=(DL2/numpyr)*1000
by id:gen AL2=(ML2-CPSIIrate)/ML2
by id:replace AL2=0 if AL2<0
by id:gen A02=1-exp(-PWGcoef*(ML2-CPSIIrate))
by id:gen A2=(AL2*DL2+A02*D02)/(DL2+D02)
gen Adeaths=totdeath*A2
collapse (sum) Adeaths=Adeaths totdeath=totdeath Dsmoking=Dsmoking, by(edu_3cat sex country year)
gen AF_PWG=Adeaths/totdeath
gen AF_simple=Dsmoking/totdeath
mkmat AF_PWG, matrix(A)
ereturn matrix A=A
end
simulate a=e(A), reps(1000) nodots seed(123): bootPGW
에서 crossposted : 링크 (http://www.statalist.org/forums/forum/general-stata-discussion/general/2438-monte-carlo-simulation-of-a-whole-matrix -using-simulate-and-eclass) Stata 포럼에서 문제를 해결하면 여기에 답을 게시 할 것입니다. – user3568812