Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: interested in tabvals

From   Michael McCulloch <>
Subject   st: interested in tabvals
Date   Sat, 12 May 2007 09:15:43 -0700

Hello Statalist members,
This -tabvals- program looks useful. I have searched the Stata site and the web without success. Is this a program that can be obtained for use?
Thank you.

thank you for sharing your program, and thanks to all statalisters who
contributed to the discussion.

Unfortunately, I have not managed to use *tabvals* successfully.

By typing:

sysuse auto, clear
replace rep78=. if rep78==1
tabvals rep78, values(1 2 3 4 5)

I get:

. tabvals rep78, values(1 2 3 4 5)
option if required

The syntax command in your code is likely to contain the information
on how to use the "if" option... but I must be missing somenthing:
*tabvals* refuses to cooperate with me... I would appreciate any help.

- Giovanni

-----Original Message-----
[] On Behalf Of
Michael Blasnik
Sent: Friday, May 11, 2007 5:10 PM
Subject: Re: st: an ordinary two-way table

I just recalled that I had written a program with the same
goal a while back and it will do what you ask:

program define tabvals
version 8.0
*! v 1.0 M Blasnik
syntax varlist( min=1 max=2) [if] [in], values(numlist)
[MISSing] * if "`missing'"!="" { local novarlist "novarlist"
marksample touse , `novarlist'
loca l var: word 1 of `varlist'
qui levels `var' if `touse', local(hasvals) `missing'
local addvals: list values - hasvals
local tempobs: word count `addvals'
if `tempobs'>0 {
local origN=_N
qui expand `tempobs'+1 in l
tempvar real
qui gen byte `real'=(_n<=`origN')
qui replace `touse'=1 in -`tempobs'/l
forvalues i=1/`tempobs' {
local obsn=`origN'+`i'
local val: word `i' of `addvals'
qui replace `var'=`val' in `obsn'

noi tab `varlist' if `touse', subpop(`real') `missing' `options'
else {
noi tab `varlist' if `touse' , `missing' `options'

Hopefully there aren't any word wrap problems or you may need
to fix this code up. It lets you specify a values numlist
that applies to the first variable in the tabulate command. It allows you to specify a second variable but does not
create new values for that one. Since it relies on Stata's
tabulate command, it provides all of the options allowed with

Michael Blasnik

----- Original Message -----
From: "Giovanni Vecchi" <>
To: <>
Sent: Friday, May 11, 2007 10:07 AM
Subject: RE: st: an ordinary two-way table

> Chris and Nick, thanks for your suggestions. As you both say, the
> problem with tabcount is that it does not allow row and
column totals.
> I'm always puzzled when I find Stata unable to offer easy answers
 > easy questions (as the one raised in my posting). Faced with the
 > failure to produce a simple two-way table, I ask myself: is it me
 > is it Stata? And my answers start looping ... "it's me",
 "it's Stata",
 > "it's me", "it's Stata",... time goes by,
 frustration/irritation start
 > off, etc...
 > A quick reaction to Nick's suggestion. In my opinion, there is an
 > issue on the opportunity cost of pursuing a Mata-based strategy.
 > guess is that it is high for most Stata users.
 > My point: ordinary two-way tables should be within the reach of
 > Mata-almost-illiterate users. Needless to say, I am an outstanding
 > member of this club.
 > A bottom line: hope StataCorp is sympathetic to my argument... :)
 > Best,
 > - Giovanni

 *   For searches and help try:
*   For searches and help try:
*   For searches and help try:

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