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]

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


From   Stephen Cranney <cranney.stephen@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Loop-within-loop error while looping over observations for a microsimulation
Date   Mon, 6 Aug 2012 08:29:50 -0600

Hi Statalisters,

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