Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: simulating data

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


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 []
Sent: Thursday, November 21, 2002 3:56 PM
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
Reply to:

*   For searches and help try:
*   For searches and help try:

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