Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Loop-within-loop error while looping over observations for a microsimulation


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Loop-within-loop error while looping over observations for a microsimulation
Date   Mon, 6 Aug 2012 15:35:55 +0100

What is -monthsofpostpartum-? -foreach- and -forvalues- won't evaluate
for you what is not evaluated otherwise. Here -monthsofpostpartum-
needs to be replaced by some constant.

Nick

On Mon, Aug 6, 2012 at 3:29 PM, Stephen Cranney
<[email protected]> wrote:

> I'm trying to write a program that involves population microsimulation.
> Each individual has a column for year and month, and the data is sorted
> accordingly. I'm trying to loop through the observations with a stochastic
> binomial function to simulate a birth occurring, but am then trying to
> simulate the months of postpartum infertility so that it doesn't have the
> individual getting pregnant twice in two months. Postpartum infertility is
> indicated by .i and all of the fertile-time data is automatically indicated
> by .f My syntax is below, but I keep getting an invalid syntax error and
> can't figure out what I'm doing wrong.
>
> Thanks in advance,
>
>
> local N = _N
> forvalues i = 1/`N' {
>     forvalues j= 0/monthsofpostpartum {
>         replace childbirth= rbinomial(1, probabilityconceive) if childbirth== .f
>         replace childbirth[_n+j]== .i if childbirth [`i'] == 1
>         }
>     }
>
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index