Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: RE: question on strings


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: question on strings
Date   Wed, 6 Aug 2003 18:11:31 +0100

Rodrigo Brice�o

> Does "proper" command exist in Stata 7?

No. The -proper()- function (not a command)
was introduced in Stata 8.

However, you can mimic it using other programs and
functions. Here is one way to do it in Stata 7.
There are probably several other ways to do it.

. use auto

* demonstration variable:

. gen str1 make_lc = ""
. replace make_lc = lower(make)

. l make_lc in 1/10

               make_lc
  1.       amc concord
  2.         amc pacer
  3.        amc spirit
  4.     buick century
  5.     buick electra
  6.     buick lesabre
  7.        buick opel
  8.       buick regal
  9.     buick riviera
 10.     buick skylark

* install -strparse- from SSC:

. ssc inst strparse

* split the variable into its "words":

. strparse make_lc, gen(make_lc)
new variables created:  make_lc1 make_lc2 make_lc3

* capitalise the initial letter of each word:

. qui foreach v of var make_lc? {
	replace `v' = upper(substr(`v',1,1)) + lower(substr(`v',2,.))
}

* put all back together again

. egen make_proper = concat(make_lc?) , p(" ")

* did it work?

. l make_proper in 1/10

             make_proper
  1.         Amc Concord
  2.           Amc Pacer
  3.          Amc Spirit
  4.       Buick Century
  5.       Buick Electra
  6.       Buick Lesabre
  7.          Buick Opel
  8.         Buick Regal
  9.       Buick Riviera
 10.       Buick Skylark

P.S. The Statalist FAQ includes this advice:

The current version of Stata is 8. Please specify if you are
using an earlier version; otherwise, the answer to your question
is likely to refer to commands or features unavailable to you.

Nick
[email protected]


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



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