Bookmark and Share

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

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

Re: st: Generating random variable with predefined characteristics

From   Maarten Buis <>
Subject   Re: st: Generating random variable with predefined characteristics
Date   Fri, 31 May 2013 17:19:43 +0200

On Fri, May 31, 2013 at 4:55 PM, Konrad Zdeb wrote:
> I would like to generate a random variable that would have the following characteristics:
>  - would take values from 1 to 34
>  - would display a strong correlation with another variable that is currently present in the data set
>  - ideally, I would like to obtain distribution that would be positively skewed, but correlation with another variable is a priority

I interpret your question such that you want your values to be
integers. In that case you can look at the binomial distribution:

*------------------ begin example ------------------
sysuse nlsw88, clear
gen p = invlogit(-3+ .1*grade)
gen var = rbinomial(33,p) + 1
corr grade var
spikeplot var
*------------------- end example -------------------
(For more on examples I sent to the Statalist see: )

Hope this helps,

Maarten L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:

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