| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: RE: repeating strings
Note that this (good) technique is correct if and
only if each person named by -name- names at most
one city in each variable. If a person was recorded as naming two
or more cities, then the last in alphabetical
order would be used to overwrite all others for that person.
Hence a more paranoid programmer would do something like
this:
foreach var of varlist city* {
qui bysort name (`var'): replace `var' = `var'[_N] if missing(`var')
bysort name (`var') : assert `var'[1] == `var'[_N]
}
The -replace- thus would overwrite missings only.
The assertion would fail if there were different city names
for each -name- as then the -sort- would shake them apart.
Nick
[email protected]
Scott Merryman
> I believe this will work:
>
> foreach var of varlist city* {
> qui bysort name (`var'): replace `var' = `var'[_N]
> }
MA V
> > I believe that there is an easy answer for my problem but I
> can't seem to
> > find it anywhere...
> > I have a table with the following format (this is a toy
> example where we
> > have the cities in which each person has lived - city1 is where each
> > person
> > lived first):
> >
> > name city1 city2 city3
> > John SF . .
> > John . Chi .
> > John . . LA
> > Mary . NY .
> > Mary Chi . .
> > ...
> >
> > What I would like to do is to fill in the missing values
> with the city
> > strings, i.e. I would like to get at the end:
> >
> > name city1 city2 city3
> > John SF Chi LA
> > John SF Chi LA
> > John SF Chi LA
> > Mary Chi NY .
> > Mary Chi NY .
> > ...
> >
*
* 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/