Monte Carlo simulation of a whole matrix in Stata -
I calculate a summary data of a group of my data (such as age, gender) with confidence intervals Would like to For that purpose, I use Monte Carlo simulation drawing value for each line in the Poisson distribution for my data and then pulling out the rows. The result of the simulation is just a value (using the return scalar in Raxas), but the whole process is completely cured, but as soon as I try to simulate more than one result (using ETRN matrix in Ecluron) I'm not working (see status code below). I get an error message: "Type mismatch error in expression: e (a)". How can I simulate the matrix of results without a more vector or more complex loop?
Many thanks! Fred
program use bootPGW, eclass "c: \ users \ 649007 \ desktop \ demetriq_PWG_edu.dta", gene id = _n sort id gene n = _n id by: gen DL2 = floor ID: gen Dsmoking = floor (rpoisson (smoking)) * ID by: GEN AL2 = (ML2) (id: gen ML2 = (dl2 / numpyr) id: General D2 = 2 = floor (rpoisson (D0)) -CDPeter) / ML2 ID: Replace AL 2 = 0 by ID: AL2 and LT; 0 ID: Gene A02 = 1-XP (-PWKFEED * (ML2-CPS II RT)): Gene A2 = (AL2 * DL2 + A2 * D02) / (DL2 + D02) gene ediths = tooth * a2 fall (zodiac) edith = adherence to toothith = toeeth dsmoking = dsmaking, by adu oakatat sex country worn) AFIPWG = adeth / toedheath genef_symal = dsmaking / TODAYTH MITTAM AFU WG, MATRIX (A) ECHRATION MATERICS A = A END EQUIPMENT A = E (A), Representative (1000) NODOT SEED (123): Boot PGW
The main part is that you e ) You can return the matrix using the ereturn post in , in which case you can short> cut _b in simulation Use. In addition I cleaned the code a bit: You do not need to do this by _n, because it is similar to a regular generated . You do not need rpoisson () around the floor () function because it already provides an integer, you are not using N, so you do not need it. , But even if you do this, you can store it as a local macro (or if you prefer a scalar) instead of a variable (column in the dataset) because it's a single number, To store in L is profane memory. program boot Pijeedblu, Icls use "C: \ Users \ 649007 \ Desktop \ Dimetiri_ PWG_edukdta", Jan DL2 = rpoisson) General D02 = rpoisson (D0) General Dsmoking = rpoisson (non) General ML2 = (DL2 / numpyr) * 1000 General AL2 = (ML2-CPSIIrate) / ML2 instead of AL2 = 0 if AL2 & LT; 0 General A 02 = 1-exp (-PWGcoef * (ML2-CPSIIrate)) General A 2 = (AL2 * DL2 + A 02 * D02) / (DL2 + D02) General Adeaths = totdeath * A2 Fall (yoga) Adeaths = Adeaths totdeath = totdeath Dsmoking = Dsmoking, /// (edu_3cat sex country year) General AF_PWG = Adeaths / totdeath General AF_simple = Dsmoking / totdeath mkmat AF_PWG, matrix (a) post an end eReturn _b, representative (1000) followed by nodots Seeds (123): bootPGW
Comments
Post a Comment