Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Duru <duru80@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: Generating Y variable immitating another regression's parameters |
Date | Wed, 15 Feb 2012 02:01:18 +0100 |
Dear all, I am trying to generate two random Y variables (continuous and binary). While generating them, I use observed predictors and try to imitate the coefficients and R-squared from a regression using an observed continuous Y. I create the binary Y using the same coefficients as the continuous Y –as shown below. I wonder if the following code for the binary variable makes sense. I wanted to have more equal split for the binary variable, but not sure if I could adjust it. Thanks! Duru ******************* Stata version 11 * GENERATE CONTINUOUS Y *** Set desired parameters local b0 = .05 local b1 = -1 local b2 = 2 local b3 = 1 local b4 = .5 local b5 = -1 local b6 = -2 local b7 = -1 local b8 = -.01 local b9 = 3 local b10 = -.8 local be = 11 set seed 1234 gen u= rnormal() gen y1=`b0'+`b1'*age2+`b2'*age3+`b3'*age4+`b4'*age5+`b5'*sex+`b6'*c2+`b7'*c3+`b8'*ausland+`b9'*a+`b10'*status +`be'*u * GENERATE BINARY Y *Set desired parameters local b0 = .05 local b1 = -1 local b2 = 2 local b3 = 1 local b4 = .5 local b5 = -1 local b6 = -2 local b7 = -1 local b8 = -.01 local b9 = 3 local b10 = -.8 local be = 11 set seed 1234 gen u= rnormal() gen p1 =`b0'+`b1'*age2+`b2'*age3+`b3'*age4+`b4'*age5 +`b5'*sex+`b6'*c2+`b7'*c3+`b8'*ausland+`b9'*a+`b10'*status +`be'*u gen p2 = exp(p1) / (1 + exp(p1)) gen byte y2 = ( uniform() < p2 ) * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/