Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: How to generate binary y?

From   Bryan Griffin <>
Subject   st: How to generate binary y?
Date   Fri, 4 May 2012 10:15:15 -0400

Here's some code I used in a do file to create clustered data for
analysis with xtlogit. Perhaps you can use some of this as a basis for
generating binary Y.

set more off
	set obs 500
	generate float z1= invnorm(uniform())
      generate n = 5
      generate id_2 = _n
      expand n
      bysort id_2: gen id_1 = _n
      generate float u0j= invnorm(uniform())*1	
      generate float x1= invnorm(uniform())
	generate y = 1 + 1*x1 + 1*z1 + u0j
	generate p = exp(y)/(1+exp(y))
	generate binary_y = uniform()<=p	
iis id_2

xtlogit binary_y x1 z1, re

Bryan Griffin
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index