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

st: RE: obtaining locals

From   "Nick Cox" <>
To   <>
Subject   st: RE: obtaining locals
Date   Thu, 25 Sep 2003 11:28:27 +0100

Lars Korsholm
> I am sure that someone know a smart way to do what I want. :-)
> the sort version:
> Is it possible to obtain the label associated to a given value?
> The long verson:
> I am writing a small tabulation program. The user (also me)
> specify some
> of the levels that a kategorical (integer) veriabel has.
> and for each of
> these chosen levels the program  produce one line of output.
> I would like the line to start with the label associated
> with the level
> and not the integer in my loop.
> i.e. something like
> program define mytab
>  syntax varname, ni(numlist ..) ..
>  foreach x  in numlist `ni' {
>     count if `varname'==`x'  & ..
>     di "level yyy:" `r(N)' ...
>     }
> end
> where yyy is the contens of the label associated with varname
> that corespond to the value `x'
> If no label is assigned, then `x' must do.

David Moore has already pointed to extended
macro functions (see help for -macro-),
and he noted carefully that his comments
were based on Stata 6.

You can now go directly to

. local lbl : label (<varname>) <value>

or even

`: label (<varname>) <value>'

In a different key, note that your tabulation
as specified above can be tackled by -tabcount-
from SSC, which will

	restrict values to a specified numlist
	display counts
	display value labels if defined


*   For searches and help try:

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