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

Re: st: constrained sum of random values

From   Eva Poen <>
Subject   Re: st: constrained sum of random values
Date   Wed, 25 Mar 2009 19:11:46 +0000


If you put such a constraint on your random values, it means that at
most 76 of them can be random; you need one value to bring the sum up
to 9900. This is very simple to do:

set obs 77
set seed 123
gen n = rnormal(125,25) in 1/76
qui sum n
replace n = 9900-r(sum) in 77

You didn't mention what kind of random values you want, i.e. which
distribution. I assumed normal distribution with mean 125 and sd of


2009/3/25 Carlo Lazzaro <>:
> Dear Statalisters,
> is there any way for imposing Stata 9.2/SE to create a variable composed of
> 77 random values so that the sum of these random values is 9900?
> Thanks a lot for your kindness and for your time.
> Kind Regards,
> Carlo
*   For searches and help try:

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