Statalist The Stata Listserver


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

Re: st: an ordinary two-way table


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   Re: st: an ordinary two-way table
Date   Sat, 12 May 2007 09:48:45 -0400

...
The program apparently wrapped in the emailing at this section:

syntax varlist( min=1 max=2) [if] [in], values(numlist)
[MISSing] * if "`missing'"!="" {  local novarlist "novarlist"
}

This should be two lines

line 1:
syntax varlist( min=1 max=2) [if] [in], values(numlist) [MISSing] *

line 2:
if "`missing'"!="" { local novarlist "novarlist"}


The second line should really be split up given more recent Stata conventions, as:

if "`missing'"!="" {
local novarlist "novarlist"
}


Michael

----- Original Message ----- From: "Giovanni Vecchi" <[email protected]>
To: <[email protected]>
Sent: Saturday, May 12, 2007 4:47 AM
Subject: RE: st: an ordinary two-way table



Michael,

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
r(198);

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-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
Michael Blasnik
Sent: Friday, May 11, 2007 5:10 PM
To: [email protected]
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 {
  preserve
  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'
 restore
 }
else {
 noi tab `varlist' if `touse' , `missing' `options'
}
end

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
tabulate.

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