[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: string functions

From   "Martin Weiss" <>
To   <>
Subject   st: AW: string functions
Date   Mon, 26 Oct 2009 13:37:34 +0100



set obs 1
gen myvar1=.
gen myvar2=.

la var myvar1 "area (cm sq)"
la var myvar2 "other area (cm sq)"


qui ds, has(varlabel)

foreach var of varlist `r(varlist)'{
	local mylabel="`:var label `var''"
	local mynewlabel=substr("`mylabel'", 1, strpos("`mylabel'","(")-1)
	la var `var' "`mynewlabel'"

//check success


-----Ursprüngliche Nachricht-----
[] Im Auftrag von Miranda Kim
Gesendet: Montag, 26. Oktober 2009 13:28
Betreff: st: string functions

I have a basic question on using string functions to do the following:
I have variable labels that have various units in brackets: (cm) (cm sq) 
etc. and I want to remove these from the label.
How can I search a string for the portion between brackets (including 
the brackets) and replace this with a blank?
For example if my variable area has the following label: "area (cm sq) 
of ..."
I want to replace the label with : "area of ..."
I have many variables so I want to automate this rather than having to 
type in individual labels...
I use stata v10
Many thanks!

*   For searches and help try:

*   For searches and help try:

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