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: i-1 in forvalues loop


From   Viktor Emonds <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: i-1 in forvalues loop
Date   Tue, 18 Oct 2011 15:55:11 +0200

Hey,

I am trying to draw a sample with random start, fixed interval systematic sampling procedure in each explicit stratum. The data in each stratum are already sorted by all the implicit stratifiers with serpentine sorting for a variable of particular interest. Now I just need to do the actual sampling and tried to start by doing the following:

use ethnicframe31                                                              //the specific explicit stratum
gen lotto=sum(studentsj3)                                                  //sum of target population
egen bal1= mean(3166.4667*runiform())                             //random starting point
forvalues i=2/15 {                                                          //Draw ' lotto balls' by adding the fixed interval
gen bal`i'= bal`i-1'*3166.4667
}

gen winnaar=0                                                                 //Identify ' winning'  schools
forvalues i=1/15{
replace winnaar=1 if inrange(bal`i',lotto[_n-1],lotto)
}

Apparently, the `i-1'  in the first loop is not understood. What am I doing wrong here? Thanks in advance!
Best,
Viktor
*
*   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