Statalist The Stata Listserver

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

st: Combine uppercase and lowercase text

From   Friedrich Huebler <>
Subject   st: Combine uppercase and lowercase text
Date   Wed, 21 Feb 2007 16:15:30 -0800 (PST)

My data has string variables with text in uppercase or lowercase
letters. I would like to replace observations that are identical once
capitalization is ignored (e.g., "TEXT" and "text") by the most
common spelling. In some cases there are ties. So far I have only
managed to replace all such observations by their lowercase variant,
as in the example below. I am stumped and would appreciate any advice
on how I should proceed. I use Stata 8.2.

Friedrich Huebler

gen str15 text = ""
  "some text"
  "Some Text"
  "some other text"
  "some other text"
  "Some other text"
  "Some other text"
  "SoMe TeXt"
  "SoMe TeXt"
  "Some Other Text"
local n = r(N)
forvalues i = 1/`n' {
  local t = lower(text[`i'])
  replace text = "`t'" if lower(text) == "`t'"

Bored stiff? Loosen up... 
Download and play hundreds of games for free on Yahoo! Games.
*   For searches and help try:

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