[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Carlo Lazzaro" <carlo.lazzaro@tiscalinet.it> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: R: RE: rowmean within a loop |

Date |
Mon, 22 Jun 2009 14:59:36 +0200 |

Dear Martin and Nick, thanks a lot for your kind reply and sorry for not being clear in my previous message. I am doing a probabilistic sensitivity analysis (PSA) with 10,000 simulations for each variable. I would like to obtain 10,000 s`i' simulations (that is, 10,000 s`i', expressing the monthly probability of surviving for people affected by a given disease and followed-up from 50 to 100 years of age); Then I multiply this 10,000 probabilities for the surviving expressed in a monthly base (LYS), in order to get 10,000 LYS weighted for s`i'(ie, s`i'*LYS) (where LYS =.0833333). My problem is: I would like to collect, for each month, the rowmean value of u`i', calculated across all the 10,000 simulations. Assuming for sake of simplicity that my PSA stops after 3 simulations, I would figure out a file.dta like the following one: Month s1 u1 s2 u2 s3 u3 1 .0198312 .0016526 .0189071 .00157559 .0386583 .00322152 2 .01853398 .0015445 .01767033 .00147253 .03612954 .00301079 3 .01732161 .00144347 .01651445 .0013762 .03376619 .00281385 By the way, for another research purpose, I am interested in storing in another variable, the total() per column of each u`i'. Thanks a lot for your kindness and for your time. Kind Regards, Carlo -----Messaggio originale----- Da: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Per conto di Nick Cox Inviato: lunedì 22 giugno 2009 13.03 A: statalist@hsphsun2.harvard.edu Oggetto: st: RE: rowmean within a loop The intent of the code you give is difficult to understand. It commits you to generating 20000 new variables, s1-s10000 and u1-u10000, which I doubt is what you really want. egen v`i' = rowmean(u`i') within a loop is just going to put the rowmean of one variable (that variable, identically) in another variable, which is pointless. Do start again from the beginning: 1. Explain your data. 2. Explain your problem. Nick n.j.cox@durham.ac.uk Carlo Lazzaro after typing qui forval i =1/10000 { qui g double s`i' = Surv_Pos_IFI[`i']*(1-Monthly_Pr_Death_AML_MDS_Prob) in 1 replace s`i' = s`i'[_n-1]*(1-Monthly_Pr_Death_AML_MDS_Prob) if s`i'==. qui g double u`i' = s`i'*LYS } I would like to obtain a variable where I can store the rowmeans for all the u`i'. I tried unsuccessfully to use egen v`i'=rowmean(u`i'), but this way I (obviously, I would suppose) get v`i' for each u`i', and this not help the achievement of my research purpose. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**st: AW: R: RE: rowmean within a loop***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**References**:**st: RE: rowmean within a loop***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: Bootstrapping new observations to add to an existing dataset** - Next by Date:
**st: AW: R: RE: rowmean within a loop** - Previous by thread:
**st: RE: rowmean within a loop** - Next by thread:
**st: AW: R: RE: rowmean within a loop** - Index(es):

© Copyright 1996–2022 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |