Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: copying a string variable to all rows within a group


From   <Seyi.Soremekun@lshtm.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: copying a string variable to all rows within a group
Date   Wed, 29 Feb 2012 08:28:22 +0000

Dear All,
If I have a numeric variable "oldvar" which appears on only the first row of a set of rows defined by a group variable "groupvar" (rest of oldvar rows are blank), it is easy enough to copy oldvar down all rows within groupvar:
 
bysort groupvar: egen newvar=max(oldvar) // can equally use =min(oldvar) as there is only 1 value of oldvar.
 
How might I do the same to copy a string oldvar to all rows - again it only appears once within the group, but not necessarily on the first row.
 
Seyi

Dr Seyi Soremekun
Faculty of Epidemiology and Public Health 
London School of Hygiene and Tropical Medicine
London WC1E 7HT
+442079272464



*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index