|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: Re: st: corrections to tabl, shows value labels and codes
I have comments on three different levels.
1. I have not looked closely but on the face of it, M Hollis has
(a) identified some bugs and/or made some improvements to Jeroen
Weesie's -tabl- _and_ (b) made that fact public.
Given (b), please note a protocol that is public and is documented at
<http://www.stata.com/support/faqs/res/statalist.html#relation>
as follows:
"However, StataCorp has nonexclusive rights to any program published in
the STB or SJ, while anything placed in the SSC Archive is tacitly put
in the public domain. In practice, you can probably take anything
published in either medium and modify it as you will — especially if you
do that privately — but publicly we recommend that unless you are the
original author, you should change the name of the program, take all
blame for any limitations your changes produce, and imply that a
suitably large portion of the credit for the program belongs to the
original authors."
Although this protocol does not explicitly apply to programs accessible
on user sites, I suggest the same as good practice here, namely anyone
modifying this program as M Hollis suggests should change the name too,
and assume responsibility for the changes.
Turn it round: suppose you were the original programmer and still alive
and still accessible. It is quite likely that you would want to know
about your bugs. Of course, if your reaction is that you don't care,
then others would seem to have free scope to do what they like to your
code.
Alternatively, suppose others made changes to your program that you
don't approve and/or introduced further bugs. Your reaction would
be, most probably, that those others really are now responsible
(in various senses of that word). Changing the name and assuming
the blame is then the right thing to do.
In addition, could at least one person doing that contact Jeroen Weesie
directly, as he is not a member of Statalist?
2. Focusing on the original problem, I see it as this:
* Some people sometimes like to see numeric codes _and_ value labels
on -tabulate- output.
M Hollis, and others, would like to see an option on -tabulate-
to do that; and, failing that, turn to user-written programs to
achieve the same end.
This may not seem controversial, except that it is. StataCorp,
I believe, would like you to agree that you are thinking about
this at the wrong level. If you add an option to -tabulate-
to show codes and value labels, then isn't there an equivalent
case for adding such an option everywhere that value labels
are shown? -- and before you know it there are little options
springing up like mushrooms, or perhaps cockroaches,
all over the shop. Now empirically it may well be that it is
mostly with -tabulate- that people want this -- typically there
is less room on graphs or model output, etc. -- but be that as
it may I would assert that adding options ad hoc like this is
not good style.
So much for the pontification, but StataCorp have provided
their solution, which is -numlabel-, as a way of adding and removing
numeric codes to and from value labels. You can do this,
naturally, before and after any command you like, not just
-tabulate-.
3. Now your reaction may be, Yes, in principle, but in practice
that is still more fiddly than I would like.
One solution is to have two sets of codes for different purposes
using -label language-.
Another is to see how much work it is to automate this working
from first principles. The basic recipe is
if a variable has value labels {
clone the variable
clone the value labels
put numbers on the labels
assign those labels to the clone
tabulate cloned variable
}
else tabulate variable as was
Here is some code. This is little tested, but may be of interest
as an attempt at a bare-bones solution to the original problem.
program njc_tabl
version 9
syntax varlist [if] [in] [fweight aweight iweight] [, * ]
quietly {
marksample touse, novarlist
count if `touse'
if r(N) == 0 error 2000
foreach v of local varlist {
local lblname : value label `v'
if "`lblname'" == "" {
noisily tab `v' if `touse' [`weight' `exp'] ///
, `options'
}
else {
tempvar varclone
tempname lblclone
clonevar `varclone' = `v' if `touse'
tempfile file1 file2
tempname in out
label save `lblname' using `"`file1'"'
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 "`lblname'" "`lblclone'"
file write `out' `"`line'"' _n
file read `in' line
}
file close `out'
do `"`file2'"'
numlabel `lblclone', add
label val `varclone' `lblclone'
noisily tab `varclone' [`weight' `exp'] ///
, `options'
drop `varclone'
}
}
}
end
Nick
[email protected]
Ben Jann
If you're interested in -tabl-, you might be interested in -fre-. See
http://www.stata.com/statalist/archive/2007-04/msg00420.html
or type
. ssc describe fre
M Hollis
> I've often been frustrated by the fact that a one-way tabulate
doesn't have the option to show both the value labels and the underlying
codes. I did a search on the statalist and found this message and its
replies:
> http://www.stata.com/statalist/archive/2007-03/msg00558.html
>
> The thread points to a user-created command, tabl, which was designed
to do exactly this. Unfortunately, as noted in the previous thread, the
command as downloaded contains errors and doesn't work properly. I'm not
much of a programmer, but I know enough to do some debugging. So, I
think I've figured out the steps necessary to fix it. To install tabl, type:
>
> net describe tabl, from(http://www.fss.uu.nl/soc/iscore/stata)
>
> in the command window and then follow instructions to install. Open
the ado file in the do-file editor or other text editor (by default it's
in c:\ado\plus\t). Then make the following changes:
>
> 1) line 26 is missing a bracket. It should read: if "`missing'" == "" {
> 2) replace line 69 ("di") with the following lines:
> di
> di in gr "`vlab'"
> di
> di in gr _col(`col1') " code | Freq Percent "
> di in gr _dup(`col1') "-" "--------+--------------------"
>
> 3)insert at about line 23 (below the line "sytax varname....") a new
line:
> marksample touse, novarlist
>
>
> That, hopefully, is all you need to do. Seems to be working fine for
me. Please let me know if it also works for you. I'm contemplating
distributing a copy of the ado to the students in my intro stats class
this fall, because it's really helpful for them to be able to see both
the labels and values. They are pretty skittish about using stata as it
is, though, so I don't want to get them confused by any bugs.
>
> Also, I should note that the ado file seems to have the initial
programming for a "compact" option, see examples at the end of the ado
file as well as the section that starts at line 54 of the updated ado
file with "if "`compact'" != "" {". As far as I can tell, though, the
local `compact' is never defined and so this option is never invoked.
The examples seem to suggest that the compact option is appropriate for
very long value labels, it's hard to tell whether it's supposed to be
automatically selected if labels are over a certain length or a command
option. It does suggest that the current version may cause problems when
used on variables with very long labels (although you can use the width
option).
*
* 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/