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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

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

Subject |
RE: st: RE: converting a string variable that has leading and embedded blanks to a numeric variable. |

Date |
Tue, 8 Feb 2005 19:26:16 -0000 |

The original variable would seem to satisfy this criterion. I am not aware that any of -sort-, -merge- or -collapse- requires numeric ids. Alternatively, gen hhid2 = subinstr(hhid, " ", "_", .) egen hhid3 = group(hhid2), label may be of some use. Nick n.j.cox@durham.ac.uk Ali Murat > My concern is that I need to transform the string hhid variable into > the numeric one If I wantto use Stata commands such as sort, merge, > collapse that all require a unique id variable for each observation- > or group. 21blank 2 and blank212 are differen hhid numebers and belong > to different households. When I use the following command > destring newhhid, replace ignore(" ") > hose two hhid numbers turned into the same numeric hhid variable hhid > that makes impossible to differentiate between them. Nick Cox > > Sorry, but what's the problem? > > Stata did what you asked. If you > > do in fact believe that the blanks > > are somehow informative, your original > > variable is the one to use. Ali Murat > > > I am trying to convert a string household > indentification variable > > > ,that has leading and embedded blanks, to a numeric one. > When I used > > > the destring command, the new numeric household > identification number > > > has no longer unique values due to leading and embedded > blanks in the > > > orÄ±ginal string household identification variable. To be more > > > precise, I would like to document what I have done so far: > > > > > > gen newhhid=hhid > > > > > > destring newhhid, replace ignore(" ") > > > > > > sort newid > > > > > > l hhid newhhid > > > > > > > > > > > > Obsnumber hhid newhhid > > > > > > 161. | 21 1 211 | > > > > > > 162. | 21 2 212 | > > > > > > 163. | 212 212 | > > > > > > 164. | 213 213 | > > > > > > 165. | 21 3 213 | > > > > > > |------------------------| > > > > > > 166. | 214 214 | > > > > > > 167. | 21 4 214 | > > > > > > > > > > > > Please note that the observation 162 and 163 have a > distinct hhid; the > > > fist has an embedded blankd, the second has a leading > blank. However, > > > after using the destring command, they have same hhid number. > > > * * 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: converting a string variable that has leading and embedded blanks to a numeric variable.***From:*Ali Murat <alimuratberker@gmail.com>

- Prev by Date:
**st: RE: Re: converting a string variable that has leading and embedded blanks to a numeric variable.** - Next by Date:
**RE: st: -update all- fails with "linestyle-p#line.style not found"** - Previous by thread:
**Re: st: RE: converting a string variable that has leading and embedded blanks to a numeric variable.** - Next by thread:
**Re: st: RE: converting a string variable that has leading and embedded blanks to a numeric variable.** - Index(es):

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