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

RE: st: RE: about stacked mean bar chart

From   "Nick Cox" <>
To   <>
Subject   RE: st: RE: about stacked mean bar chart
Date   Fri, 1 Nov 2002 16:03:38 -0000

Roger Harbord

> > foreach v of var v1 v2 v3 {
> > 	bysort v4 : egen mean`v' = mean(`v')
> > 	_crcslbl mean`v' `v'
> > }
> <snip>
> Okay Nick, I have to ask - how did you know that _crcslbl
> existed and what
> it did?  There are no help files for the _ commands.  Only a couple
> (literally) are documented in [P].  I've gathered that
> programs beginning
> with _g are -egen- functions.  What are all the programs
> beginning with
> _crc?

I picked up this knowledge from rummaging around
inside official Stata ado files. And if you look
inside you can see what it does. The code is (nearly)
its own help.

There are lots of undocumented commands, some
so undocumented that perhaps nobody outside
Stata Corp knows about them. Some are old commands
on their way out; some are new commands on their
way in; many are too technical or too dangerous
to be documented; some just never got documented
somehow; and so on.

This was one, I believe, written originally for Stata
Corp's own programmers as a utility; that's my guess
also at the most common reason for something being
undocumented. Stata Corp was previously called
"Computing Resource Center" and its prime business
function was selling computer time, but then
a sideline called Stata started to do rather
well, and ... Well, someone some day may write
a history of Stata, but that explains the otherwise
cryptic "crc". "slbl" can be understood as "same

As far as undocumented commands are concerned,
there is no guarantee that they will be
included within future versions of official Stata,
but I suspect this one will lie around for the foreseeable
future, as it is probably invoked by quite
a lot of programs.

In this particular example, I wanted to
keep the code as simple as possible
and give the questioner a simple way
to copy variable labels, without the
first principles solution (although
that would be two lines rather than one)
or without recommending -copydesc-
on SSC (which is more general than
-_crcslbl- -- and not compatible with it).

> On a (possibly) related point:
> Does anyone know how to make a copy of a value label, so
> that I can then
> modify one or more of the # to label correspondences ?
> Say I decide to combine the upper groups of a grouped
> income variable
> (because I'm analysing a subpopulation with few rich people, say):
> . gen income5=income10
> . recode income5 5/max=5
> Now I need to copy make a copy of the value label
> associated with income10
> and modify the label corresponding to 5.  (I don't want to
> modify the
> original label as I still want to keep income10 in the
> dataset too). Surely
> there should be a way of doing this without writing a loop starting
> -forvalues i=1/4- ?  None of the -label- commands will do
> this, and Nick
> Cox's -labcopy- on SSC is designed to do something slightly
> different.
> Might there be an _ command to do this too?  How would I
> find out?  I had a
> quick look in C:\Program Files\StataSE\ado\base\_ and
> discovered there are
> a lot of .ado files but no .hlp files!

Here is one way to clone a value label:

*! NJC 1.0.0 1 Nov 2002
program def labvalclone
	version 7
	args old new garbage
	if "`old'" == "" | "`new'" == "" | "`garbage'" != "" { /*  */
		di as err "syntax is: " /*
		*/ as txt "labvalclone {it:vallblname newvallblname}"
		exit 198
	if "`new'" == "label" | "`new'" == "define" { /* */
		di as err "don't use the name `new'!"
		exit 198

	tempfile file1 file2
	qui label save `old' using `"`file1'"'

	tempname in out
	file open `in' using `"`file1'"', r
	file open `out' using `"`file2'"', w
	file read `in' line

	while r(eof) == 0 { /* */
		local line: subinstr local line "`old'" "`new'"
		file write `out' `"`line'"' _n
		file read `in' line
	file close `out'

	qui do `"`file2'"'

Syntax is

labvalclone <existing valuelabelname> <new value label clone>


*   For searches and help try:

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