Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
"Dr. Martin Weiss" <martin.weiss1@gmx.de> |

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

Subject |
AW: st: AW: Carry over information on time-invariant covariate to all observations of a household? |

Date |
Tue, 3 Aug 2010 12:51:14 +0200 |

<> This code shows that my approach is considerably faster (60 vs. 150 seconds) than the alternative one. This could also depend on the number of processors, so you can vary it in the first two lines of the code: ************* //change # of processors //set processors 2 //alternative 1 clear* qui{ set mem 1500m inp int(HH Year X) 1 1990 5 1 1991 . 1 1992 . 2 1990 . 2 1991 3 2 1992 . 3 1990 . 3 1991 . 3 1992 2 end compress //Create large dataset expand 5000000 timer clear timer on 1 bys HH: egen X2 = max(X) replace X = X2 timer off 1 qui timer list noi di in r "# of processors: " c(processors) /* */ _n "Alternative 1 (egen, max()) takes: " r(t1) " seconds" timer clear } //alternative 2 clear* qui{ set mem 1500m inp int(HH Year X) 1 1990 5 1 1991 . 1 1992 . 2 1990 . 2 1991 3 2 1992 . 3 1990 . 3 1991 . 3 1992 2 end compress //Create large dataset expand 5000000 timer clear timer on 1 bys HH (X): replace X = X[1] timer off 1 qui timer list noi di in r "# of processors: " c(processors) /* */ _n "Alternative 2 (replace X = X[1]) takes: " r(t1) " seconds" timer clear } ************* HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Jen Zhen Gesendet: Dienstag, 3. August 2010 11:02 An: statalist@hsphsun2.harvard.edu Betreff: Re: st: AW: Carry over information on time-invariant covariate to all observations of a household? Great, thanks! On Tue, Aug 3, 2010 at 10:35 AM, Dr. Martin Weiss <martin.weiss1@gmx.de> wrote: > > <> > > Use > > ************* > bysort HH (X): replace X = X[1] > ************* > > then! > > > HTH > Martin > > -----Ursprüngliche Nachricht----- > Von: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Jen Zhen > Gesendet: Dienstag, 3. August 2010 10:29 > An: statalist@hsphsun2.harvard.edu > Betreff: st: Carry over information on time-invariant covariate to all > observations of a household? > > Dear Listers, > > suppose I have a panel with dimensions Household and Year. I have the > time-invariant household characteristic X. Information on it is > currently given for each household in only one of the years, but I > would like to carry over this information to all observations of each > household. > > To illustrate, the dataset looks like this: > > HH Year X > 1 1990 5 > 1 1991 . > 1 1992 . > 2 1990 . > 2 1991 3 > 2 1992 . > 3 1990 . > 3 1991 . > 3 1992 2 > > and I would like to fill in the missing values. > > Currently my way of doing it is this: > - bysort HH: egen X2 = max(X) - > - replace X = X2 - > > However, in a large dataset running this command takes forever, so I > am wondering whether there is a faster way to do this? > > Many thanks, > JZ > * > * 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/ * * 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: Carry over information on time-invariant covariate to all observations of a household?***From:*Jen Zhen <jenzhen99@gmail.com>

**Re: st: AW: Carry over information on time-invariant covariate to all observations of a household?***From:*Jen Zhen <jenzhen99@gmail.com>

- Prev by Date:
**Re: st: egen rowmeaan** - Next by Date:
**st: AW: egen rowmeaan** - Previous by thread:
**Re: st: AW: Carry over information on time-invariant covariate to all observations of a household?** - Next by thread:
**Re: st: Carry over information on time-invariant covariate to all observations of a household?** - Index(es):