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

From |
"Nuno" <liststata@gmail.com> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: Running a regression for a subset of observations issue |

Date |
Sat, 7 Jul 2007 15:21:26 +0100 |

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: sysuse auto, clear keep if rep78==3 gen i=_n jacknife _b, keep: reg mpg weight displacement turn reg mpg weight displacement turn if i!=1 Regress reports the following coefficients: ---------------------------------------------------------------------------- -- mpg | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+-------------------------------------------------------------- -- weight | -.0020761 .0016688 -1.24 0.225 -.005513 .0013608 displacement | -.0062576 .0119518 -0.52 0.605 -.0308729 .0183577 turn | -.3671771 .1733158 -2.12 0.044 -.7241277 -.0102266 _cons | 42.77554 5.130264 8.34 0.000 32.20957 53.34152 ---------------------------------------------------------------------------- -- While the results for using jacknife for the first observation are: _b_weight _b_displacement _b_turn _b_cons .0009151 -.038999 -.3450164 40.28076 After taking a look to the manual, it seems that jacknife calculates pseudovalues, which isn't what I need. I just need to use the information of the rest of the firms on the same SIC code (excluding the company being analyzed) to calculate the expected value of the company being analyzed. ************* Begin Code ************* sysuse auto, clear gen mpg_excl=. gen cweight=. gen cdisplacement=. gen cturn=. gen ccons=. foreach n of numlist 2/5 { preserve drop if rep78!=`n' qui gen i=_n qui sum mpg local nobs=r(N) foreach j of numlist 1/`nobs' { tempvar a b c d qui regress mpg weight displacement turn if i!=`j' qui predict hat qui replace mpg_excl = hat if i == `j' qui drop hat qui gen `a'=_b[weight] qui gen `b'=_b[displacement] qui gen `c'=_b[turn] qui gen `d'=_b[_cons] qui replace cweight=`a' if i==`j' qui replace cdisplacement=`b' if i==`j' qui replace cturn=`c' if i==`j' qui replace ccons=`d' if i==`j' drop `a' `b' `c' `d' } qui gen est=ccons+cweight*weight+cdisplacement*displacement+cturn*turn save c:\file`n'.dta, replace restore } ************* End Code ************* -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Steichen, Thomas J. Sent: sexta-feira, 6 de Julho de 2007 21:34 To: statalist@hsphsun2.harvard.edu Subject: st: RE: Running a regression for a subset of observations issue 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 steicht@rjrt.com ----------------------------------- -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nuno Sent: Friday, July 06, 2007 4:08 PM To: statalist@hsphsun2.harvard.edu 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/ * * 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/

**Follow-Ups**:**Re: st: RE: RE: Running a regression for a subset of observations issue***From:*"Austin Nichols" <austinnichols@gmail.com>

**References**:**st: Running a regression for a subset of observations issue***From:*"Nuno" <liststata@gmail.com>

**st: RE: Running a regression for a subset of observations issue***From:*"Steichen, Thomas J." <SteichT@rjrt.com>

- Prev by Date:
**RE: st: Invalid file specification** - Next by Date:
**Re: st: RE: RE: Running a regression for a subset of observations issue** - Previous by thread:
**st: RE: Running a regression for a subset of observations issue** - Next by thread:
**Re: st: RE: RE: Running a regression for a subset of observations issue** - Index(es):

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