Statalist


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

st: RE: RE: Using While Loops to Sample Decimal Values and Stata Programming Support?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Using While Loops to Sample Decimal Values and Stata Programming Support?
Date   Tue, 13 Jan 2009 18:00:44 -0000

I'd tweak that advice. 

I'd use 

forval i = 0/10 { 


} 

And divide by 10 within the loop. That way you are less likely to get
bitten by small binary/decimal precision issues. 

generate x = (_n -1 in 1/101
gen dmaxis = x / 100

could be just that 

gen dmaxis = (_n - 1) / 100 in 1/101 

(Note the extra parenthesis.) 

Nick 
[email protected] 

Martin Weiss

Re your -while- loop: Use -forvalues b=0(0.1)1- if the values you want
are
regularly spaced. Otherwise, -foreach- will happily take -any_list- that
you
supply to it. -egen, fill()- may be helpful for your first task :-)

John Ayers

Please see my question embedded in the code (in all caps as a
comment). 

estsimp regress drinking accult asuport2 ac_sup amodel2 ac_mod ///
edu work married age, genname (dmrate)
generate ploo = .
generate pmdd = .
generate phii = .
generate x = (_n -1 in 1/101
gen dmaxis = x / 100
******IS THERE A BETTER METHOD TO DO THE ABOVE 2 LINES IN A SINGLE
LINE OF CODE?, I.E. GEN A VARIABLE .01 .02 ... .99 1.00?
setx ac_sup $simac_sup  ac_mod $simac_mod  ///
(asuport2 accult edu work married age) mean
local b = 0
while `b' <= 1 {
*****HOW DO I GET THIS TO SAMPLE 0.0 .1 .2 .3 ... .9 1.0 OR SOME OTHER
DECIMAL VALUE, INSTEAD OF ONLY 0 AND 1?*****
   setx amodel2 `b'
   simqi, genev(pii)
   _pctile pii, p(5,50,95)
   replace ploo = r(r1) if dmaxis==`b'
   replace pmdd = r(r2) if dmaxis==`b'
   replace phii = r(r3) if dmaxis==`b'
   drop pii
   local b = `b' + 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index