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]

From |
"Philip Hantschk" <hantph96@gmx.at> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: assigning same number to slightly different string var. |

Date |
Tue, 01 Nov 2011 12:43:50 +0100 |

Thanks for the quick answer. i work with stata 8, so i had to use index( instead of strpos(. It works fine, but i have a little problem left. For example an index is called FTSE Europe and another FTSE Europe ex UK. These are 2 different Indices and I want to assign different numbers, but when i write replace newvar = 1 if index(myvar, "FTSE Europe") it changes both. As I write this message I think I have a solution. I first change all FTSE to 1, then FTSE Europe to 1, then FTSE Europe ex UK to 2, then FTSE Europe USD to 3 etc. From short to long. What do you think of that idea? or is there an easier way? Philip Hantschk -------- Original-Nachricht -------- > Datum: Tue, 1 Nov 2011 11:02:22 +0000 > Von: Nick Cox <n.j.cox@durham.ac.uk> > An: "\'statalist@hsphsun2.harvard.edu\'" <statalist@hsphsun2.harvard.edu> > Betreff: st: RE: assigning same number to slightly different string var. > You want a new variable, which could be constructed like this > > gen newvar = . > replace newvar = 1 if strpos(myvar, "500") > replace newvar = 2 if strpos(myvar, "Dax") > ... > > -if strpos(,)- is equivalent to -if strpos(,) > 0-. > > tab myvar if missing(newvar) > > will tell you what you missed. > > You will also want to define value labels and assign them. > > Nick > n.j.cox@durham.ac.uk > > Philip Hantschk > > i have a set of data containing names of indices, like S&P 500, Dax 30 > etc. I want to assign numbers to the indices, so that S&P 500=1, Dax 30=2 etc. > The problem is, that the in the observations, S&P 500 has different ways > of writing, e.g. Standard and Poor's 500, S&P 500, S&P 500 Index, etc. > > My question is, is there a way to assign numbers automatically, like tell > Stata to give every observation that contains "500" the "1". > > > * > * 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/ -- NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie! Jetzt informieren: http://www.gmx.net/de/go/freephone * * 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/

**Follow-Ups**:**RE: st: RE: assigning same number to slightly different string var.***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: assigning same number to slightly different string var.***From:*"Philip Hantschk" <hantph96@gmx.at>

**st: RE: assigning same number to slightly different string var.***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: assigning same number to slightly different string var.** - Next by Date:
**st: bootstrap reject()** - Previous by thread:
**st: RE: assigning same number to slightly different string var.** - Next by thread:
**RE: st: RE: assigning same number to slightly different string var.** - Index(es):