# Re: st: Programming question?

 From Joseph Coveney <[email protected]> To Statalist <[email protected]> Subject Re: st: Programming question? Date Wed, 22 Oct 2003 22:45:15 +0900

```Antonio Rodrigues Andres wrote:
----------------------------------------------------------------------------

I run this regression for grouped data logistic regression models where
zvars is a set of individual dummies

glogit ntcrimes pop cl income1 pyoung pforeign unempl den \$zvars

I try to replicate the analysis step by step

lpe =log (ntcrimes/pop/(1-ntcrimes/pop))

regress lpe income1 cl pyoung pforeign unempl den \$zvars
predict flpe %get predicted values
gen eflpe= exp(flpe)
gen fpflpe=eflpe/(1+eflpe) /logits

gen v=1/((ntcrimes*fpflpe)*(1-fpflpe)) /variance
gen wt=1/v /weights are inversely proportional to variances
regress lpe cl income1 pyoung pforeign unempl den \$zvars [aweight = wt]

I got different results, somebody knows why?

Regards

Antonio

----------------------------------------------------------------------------

It's not clear why Antonio is using the predicted values from -regress- in
the creation of weights for a successive round of -regress- instead of using
the formula for weights given in the user's manual.

In any event, -glogit- and step-by-step weighted least squares regression
give the identical results when I try it.

Joseph Coveney

----------------------------------------------------------------------------

clear
set more off
set seed 20031022
set obs 20
generate byte pop = 100
generate byte ntcrimes = _n * 5 - 1
foreach var of newlist cl income1 pyoung pforeign unempl den {
generate float `var' = uniform()
}
forvalues i = 1/3 {
generate zvar`i' = uniform() > 0.5
}
// begin here
generate double lpe =log( ntcrimes / (pop - ntcrimes) )
generate double wt = ntcrimes * (pop - ntcrimes) / pop
glogit ntcrimes pop cl income1 pyoung pforeign unempl den zvar*
regress lpe cl income1 pyoung pforeign unempl den zvar* [aweight = wt]
exit

----------------------------------------------------------------------------

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