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]
Re: st: Generating random variable with predefined characteristics
From
Maarten Buis <[email protected]>
To
[email protected]
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:
http://www.maartenbuis.nl/example_faq )
Hope this helps,
Maarten
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/