Here's a variation on that using the auto dataset:
sysuse auto
cap drop mpg_exc
gen mpg_excl = .
foreach n of numlist 1/5 {
qui regress mpg weight displacement turn if rep78 != `n'
qui predict hat
qui replace mpg_excl = hat if rep78 == `n'
qui drop hat
}
l mpg mpg_excl rep78
-----------------------------------
Thomas J. Steichen
[email protected]
-----------------------------------
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nuno
Sent: Friday, July 06, 2007 4:08 PM
To: [email protected]
Subject: st: Running a regression for a subset of observations issue
Hello everyone,
Does anyone know if Stata is able to cyclically run n regressions on a n
observations sample, but at each ith cycle the ith observation is excluded
from the sample that will be used in the estimation?
The idea is the following: I have a sample of firms which are classified in
a particular SIC code. There is a model (Jones (1991)) that for each firm in
a given SIC estimates a regression based on the firms that compose that SIC,
excluding the firm being analyzed and then uses the estimated coefficients
to determine the expected value of a given variable for the excluded firm.
This might seem confuse, but the steps are quite straightforward (although I
can't implement it in Stata...).
So imagine we have in a given SIC code 10 companies. Then, the procedure
would do the following:
1. Run the regression Y=a0+a1*X1+a2*x2 and obtain the coefficients estimates
for all the 9 observations excluding the 1st one;
2. Use the estimated coefficients to determine the expected value of Y for
the first firm;
3. Repeat 1 and 2 for the 2nd, 3rd, 4th ... firms in that SIC, excluding the
2nd, 3rd, 4th ... firm in each step.
Controlling for each SIC code is easy (just use -foreach-) but I'm unable to
implement steps 1-3...
Any ideas?
Best
Nuno
*
* 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/
-----------------------------------------
CONFIDENTIALITY NOTE: This e-mail message, including any
attachment(s), contains information that may be confidential,
protected by the attorney-client or other legal privileges, and/or
proprietary non-public information. If you are not an intended
recipient of this message or an authorized assistant to an intended
recipient, please notify the sender by replying to this message and
then delete it from your system. Use, dissemination, distribution,
or reproduction of this message and/or any of its attachments (if
any) by unintended recipients is not authorized and may be
unlawful.
*
* 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/