[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: Running a regression for a subset of observations issue

From   "Austin Nichols" <>
Subject   Re: st: RE: RE: Running a regression for a subset of observations issue
Date   Sat, 7 Jul 2007 11:01:41 -0400

Your tweak of Thomas's code introduces potential error by using
-summarize- and r(N), which if you had
obs mpg
1     9
2     .
3     7
4     6
would step through obs 1, 2, and 3.  It also uses float precision and
is less efficient in terms of memory and speed than Thomas's code. Try
this instead:

sysuse auto
cap drop mpg_excl
foreach newvar in mpg_excl bwei bdisp bturn bcons {
g double `newvar' = .
levelsof rep78, local(rvals)
sort rep78
g long i=_n
foreach r of local rvals {
su i if rep78 == `r', meanonly
forv i=`r(min)'/`r(max)' {
 cap regress mpg weight displacement turn if rep78==`r' & i!=`i'
 cap predict hat
 cap replace mpg_excl = hat in `i'
 cap drop hat
 cap replace bwei=_b[weight] in `i'
 cap replace bdisp=_b[disp] in `i'
 cap replace bturn=_b[turn] in `i'
 cap replace bcons=_b[_cons] in `i'
l i rep78 mpg_excl b*, noo sepby(rep78)

On 7/7/07, Nuno <> wrote:
Thank you everyone for all the suggestions. I was able to tweak Thomas's
code and get the result I pretended (see code below):
As for the use of the jacknife estimator, I'm not sure if it is doing the
correct estimation (or at least what I need). For rep78=3 and just for the
first observation I get:

*   For searches and help try:

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