program define gr_log
version 6.0
* syntax [,a(0) b(1.1) xunits(20)]
* graph_log a b
* graph_log a b, xunits(50)
* make parameters for equation
* local xunits =
* local a = `1'
* local or = `2'
* local b1 = ln(`or')
local a = `1'
local or = `2'
local xunits = `3'
local b1 = ln(`or')
* make summary of logistic data from equation
clear
set obs `xunits'
generate x = _n - ((`xunits'/2))
gen score = `a' + x * `b1'
generate pgty = 1 - 1/(1 + exp(score))
* graph logistic curve
graph pgty x, c(ll) s(.)
more
* make actual logistic data from summary percentages
gen count1 = round(100*pgty,1)
gen count0 = round(100*(1-pgty),1)
gen odds = count1 / count0
gen oddsr = odds[_n] / odds[_n-1]
* here is x, the number of times it happened (count1) did not happen (count0)
* the odds (odds) and odds ratio (oddsr)
listblck x count1 count0 odds oddsr
more
* make the individual data
reshape long count, i(x) j(y)
expand count
keep x y
* show the tabulations of the individual data
tabulate x y
more
* run the logistic regression
logistic y x
* note the odds ratio is close to your odds ratio
logit
* if we wanted, we could contract the data, reshape it, and go back and
* get the odds ratios from the raw data manually (as we did above)
* contract x y , freq(count)
* reshape wide count, i(x) j(y)
end