[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"#FANG ZHENG#" <FANG0031@ntu.edu.sg> |

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

Subject |
RE: st: RE: RE: AW: Compute mean for groups leaving one member out |

Date |
Sat, 24 Oct 2009 22:17:41 +0800 |

Yes, I have come across the same problem! I am new in the statalist, and I hope I can learn from the group discussion. However, I find that "=2C, gen country=3D_n" etc. is hard to understand... Anyone explain? Thanks a lot! Best, Zheng -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss Sent: Saturday, October 24, 2009 8:12 PM To: statalist@hsphsun2.harvard.edu Subject: RE: st: RE: RE: AW: Compute mean for groups leaving one member out <> Am I the only one experiencing weird characters when reading messages from "kokootchke", a.k.a Adrian? Like "=2C" and so on... Makes it difficult to read them... HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of kokootchke Sent: Samstag, 24. Oktober 2009 06:37 To: statalist Subject: RE: st: RE: RE: AW: Compute mean for groups leaving one member out <000201ca5407$fdb4cfb0$f91e6f10$@weiss1@gmx.de> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Thank you=2C Martin and NIck. Your suggestions worked beautifully. The only= problem I had was that I think that Martin's code takes the average for al= l other countries.. but including ALL quarters across years (so=2C for all = first quarters=2C for all second quarters=2C etc. I think the code should s= ay > bys country quarter: egen totalicrg=3D /* > */ total(icrg) > bys country quarter: egen numobs=3D /* > */ count(icrg) but other than that=2C everything worked perfectly. THanks a lot! Adrian ---------------------------------------- > From: martin.weiss1@gmx.de > To: statalist@hsphsun2.harvard.edu > Subject: st: RE: RE: AW: Compute mean for groups leaving one member out > Date: Fri=2C 23 Oct 2009 19:41:02 +0200 > > > <> > " But also keep track of missing values too." > > > Very true=2C and an obvious omission in the rush this morning. As an > economist=2C I often fall prey to the notion of a perfect world=2C market= =2C model > whatever... > So here is my modified code that takes account of the missing thing. Note > that I voluntarily introduce the missingness with the -drop- command in t= he > middle of the code section... > > > > ******* > clear* > set obs 40 > > gen country=3D_n > gen quarter=3Dquarterly("1990:1"=2C "YQ") > > expand 68 > bys country: /* > */ replace quarter=3Dquarter+_n-1 > format quarter %tq > > gen icrg=3Drnormal(10=2C100) > > drop if runiform()<.1 > > //calculate mean > bys quarter: egen totalicrg=3D /* > */ total(icrg) > bys quarter: egen numobs=3D /* > */ count(icrg) > //divide by # of countries-1 > gen mymean=3D(totalicrg-icrg)/ /* > */ (numobs-1) > > //10 random checks... > > forv i=3D1/10{ > local a=3D 1+int(`c(N)'*runiform()) > l country quarter mymean in `a' > su icrg if quarter=3D=3Dquarter[`a'] /* > */ & country!=3Dcountry[`a'] > } > ******* > > > HTH > Martin > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox > Sent: Freitag=2C 23. Oktober 2009 19:31 > To: statalist@hsphsun2.harvard.edu > Subject: st: RE: AW: Compute mean for groups leaving one member out > > In words=2C you get > > 1. the total of every value but one value > > 2. the number of values - 1 > > and divide. But also keep track of missing values too. > > Nick > n.j.cox@durham.ac.uk > > Martin Weiss > > "Could you suggest a simple way of doing this?" > > > > Taking a cue from Nick`s FAQ cited earlier: > > > ************* > clear* > set obs 40 > > gen country=3D_n > gen quarter=3Dquarterly("1990:1"=2C "YQ") > > expand 68 > bys country: /* > */ replace quarter=3Dquarter+_n-1 > format quarter %tq > > gen icrg=3Drnormal(10=2C100) > > //calculate mean > bys quarter: egen totalicrg=3D /* > */ total(icrg) > //divide by # of countries-1 > gen mymean=3D(totalicrg-icrg)/39 > > //10 random checks... > > forv i=3D1/10{ > local a=3D 1+int(`c(N)'*runiform()) > l country quarter mymean in `a' > su icrg if quarter=3D=3Dquarter[`a'] /* > */ & country!=3Dcountry[`a'] > } > ************* > > > > HTH > Martin > > > -----Urspr=FCngliche Nachricht----- > Von: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von kokootchke > Gesendet: Freitag=2C 23. Oktober 2009 07:39 > An: statalist > Betreff: st: Compute mean for groups leaving one member out > > Dear all: > > I have a panel dataset of 40 countries at quarterly frequency from 1990:1= to > 2006:4. I would like to compute the average of a variable (called icrg) f= or > all countries in a given time period. My problem is that in doing this > computation=2C I would like to leave one country out of the calculation. > > For example=2C in period 1990:1 for Mexico=2C I would like to compute the > average of icrg for ALL other countries in this period EXCLUDING Mexico. > > Could you suggest a simple way of doing this? > > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ =20 _________________________________________________________________ Windows 7: Simplify your PC. Learn more. http://www.microsoft.com/Windows/windows-7/default.aspx?ocid=3DPID24727: :T:= WLMTAGL:ON:WL:en-US:WWL_WIN_evergreen1:102009= * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Random walk simplex***From:*"Akshay Shanker" <Akshay.Shanker@standards.org.au>

**st: Compute mean for groups leaving one member out***From:*kokootchke <kokootchke@hotmail.com>

**st: AW: Compute mean for groups leaving one member out***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: RE: AW: Compute mean for groups leaving one member out***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**RE: st: RE: RE: AW: Compute mean for groups leaving one member out***From:*kokootchke <kokootchke@hotmail.com>

**RE: st: RE: RE: AW: Compute mean for groups leaving one member out***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**st: graph interaction in survival analysis** - Next by Date:
**RE: st: RE: RE: AW: Compute mean for groups leaving one member out** - Previous by thread:
**RE: st: RE: RE: AW: Compute mean for groups leaving one member out** - Next by thread:
**st: AW: Compute mean for groups leaving one member out** - Index(es):

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