Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: simulating data with a random binomial distribution


From   Shawn Bauldry <[email protected]>
To   [email protected]
Subject   st: simulating data with a random binomial distribution
Date   Fri, 08 Sep 2006 12:51:05 -0400

Hi all,

I'm trying to run a series of simulations to examine the distribution of coefficients in a logistic regression (note: this is part of a class, but not homework or related to any sort of grade). I would like to make the outcome variable dichotomous and a function of three other variables plus some variation.

I've tried the following approach (code below), but cannot figure out how to generate the outcome variable with a binomial distribution. I found Hilbe's random number generator programs, but they do not appear to allow me to specify the outcome variable as a function of three other variables.

Any advice people have on how to create the outcome variable or a better approach to the problem in general would be much appreciated.


-Shawn


*** Set desired parameters
local b0 = 0.5
local b1 = 1.0
local b2 = 3.0
local b3 = -4.0

*** Generating population data of 10,000 cases
set obs 10000

forvalues i = 1/3 {
gen x`i' = uniform()
}

gen p1 = `b0' + `b1'*x1 + `b2'*x2 + `b3'*x3
gen p2 = exp(p1) / (1 + exp(p1))

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* 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