# st: RE: simulating data

 From "FEIVESON, ALAN H. (AL) (JSC-SD) (NASA)" To "'statalist@hsphsun2.harvard.edu'" Subject st: RE: simulating data Date Thu, 21 Nov 2002 16:23:38 -0600

```Sherry

Suppose you have a data set where x1, ..,xp are your independent variables
(including dummies for treatment(s)). Then for logistic regression
coefficients c0, c1, c2,..,cp  issue the following commands:

gen z = c0 + c1*x1 +.... + cp*xp
gen p = exp(x)/(1+exp(z))
gen y=uniform()<=p

z is the "xb", the linear predictor
p is the probability that y=1
The last statement generates random values of y that are 0 with probability
1-p and 1 with probability p.

It's up to you to set up the data set with the x's and to specify the values
of the coefficients (the c's). They can be eiher Stata variables (a waste of
space) or scalars or local macros.

Al Feiveson

-----Original Message-----
From: Sherry Weitzen [mailto:Sherry_Weitzen@brown.edu]
Sent: Thursday, November 21, 2002 3:56 PM
To: STATALIST
Subject: st: simulating data

I feel very naive.. I'd like to simulate data from a logistic model with
several independent variables (including a treatment variable and several
confounders).  I have no idea where to start.  Please advise.  thank you.

Sherry Weitzen
Department of Community Health
Brown University, Box G
Providence RI 02912
401-863-9215

*
*   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/
*
*   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/
```