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

st: RE: string functions

From   "Nick Cox" <>
To   <>
Subject   st: RE: string functions
Date   Mon, 26 Oct 2009 12:35:24 -0000

Personally, I think it is poor practice to omit units of measurement. (I
am just revising a lecture on graphics in which mentioning units is a
key point.)  

That said, you need extended macro functions. Start at -help macro-. 

Either get your variable names into a local macro, e.g. by using -ds-.

foreach v of local varlist { 
	local label : var label `v' 
	local label : subinstr local label "(cm sq)" "", all 
	local label : subinstr local label "(cm)" "", all 
	label var `v' "`label'" 

Or, naturally, 

foreach v of var <whatever> { 

Many people call () parentheses, or possibly round brackets, [] brackets
or square brackets, {} braces, or curvy brackets. I think the
parentheses terminology is more precise; just referring to brackets can
be ambiguous. 


Miranda Kim

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

*   For searches and help try:

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