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

RE: st: RE: Triming labels.


From   "David Harrison" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Triming labels.
Date   Mon, 15 Nov 2004 09:14:38 -0000

To answer your original question (ie how to remove spaces) but for value labels rather than variable labels, the following code will remove all blanks from all value labels (that are in use):

foreach v of varlist _all {
	local vall : value label `v'
	if "`vall'"!="" {
		qui levels `v', local(lev)
		foreach l of local lev {
			local lab : label `vall' `l'
			label define `vall' `l' "`=subinstr("`lab'"," ","",.)'", modify
		}
	}
}

Nick quite rightly points out that this might not be the best approach for your problem.

David

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 12 November 2004 17:19
To: [email protected]
Subject: Re: st: RE: Triming labels.


Thanks David.

This solution is to label a variable. What if you want to save as a macro?
I try your suggestion but it returns missing.

In fact, I want to put the label in a local macro. I am doing something like
this:


prog mytab

...

qui tabstat `varlist' [`weight' `exp'], stats(mean) long save
mat M=r(StatTot)
local matvar "National"

foreach i in urban region sex marstat {
       cap confirm numeric `i'
       qui {
               lab li `i'
               local min = r(min)   /*To get the minimum value*/
               local max=r(max) /*To get the maximum value*/
        }

qui tabstat `varlist' [`weight' `exp'], stats(mean) by(`i') long save
      forval j=`min'/`max' {
               local lab`j': label `i' `j'
               local matvar "`matvar' `lab`j''"
              mat M= M \r(Stat`i')
        }
    }
}
mat M = M'
local matvar: list uniq matvar
mat colnames M = `matvar'
mat li M, f(%4.3f)
end

I am getting conformability error because the labels have blanks.

Best regards.


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