One way to tackle this -- and I think the easiest -- is just
to write a wrapper like this:
program catploti
version 8
preserve
tabi `0'
catplot bar row col [fw=pop]
end
and to call it like this
catploti 15 8\ 3 47, col chi2 replace
Note: the -replace- is essential.
So there are three steps:
1. -preserve- the data. (A -restore- later is automatic.)
2. Call up -tabi- with whatever arguments were given.
3. Call up -catplot- with the variables produced
by -replace-.
The weakness of this design is how to pass options
to -catplot-. That can be done, with more programming
effort, or if you have favourite defaults you
can just wire them into the wrapper. A percent option
is a case in point.
Or, to put it another way, you could write
two or three wrappers with different behaviour.
Nick
[email protected]
[email protected]
>
> I am making quite heavy use of -catplot-, available on SSC,
> recently. This
> nice program by Nick Cox (Thank you, Nick, once again!) plots a
> categorical variable, in frequencies or percents, on its
> own or against another categorical variable.
>
> However, this of course only works when you have variables.
> I would like
> to do the same with the values I entered as arguments to tabi.
>
> Example:
>
> . tabi 15 8\ 3 47, col chi2
>
> +-------------------+
> | Key |
> |-------------------|
> | frequency |
> | column percentage |
> +-------------------+
>
> | col
> row | 1 2 | Total
> -----------+----------------------+----------
> 1 | 15 8 | 23
> | 83.33 14.55 | 31.51
> -----------+----------------------+----------
> 2 | 3 47 | 50
> | 16.67 85.45 | 68.49
> -----------+----------------------+----------
> Total | 18 55 | 73
> | 100.00 100.00 | 100.00
>
> Pearson chi2(1) = 29.7361 Pr = 0.000
>
>
> Now I would like to have the plot output just the same as
> -catplot-,
> something like this:
>
>
> |
> | 85.5
> | 83.3 +
> | + +
> | + +
> | + +
> | + +
> | + +
> | + +
> | + 16.7 +
> | + + 14.6 +
> | + + + +
> | + + + +
> | + + + +
> |--------------------------------------------
> row=1 row=2 row=1 row=2
>
>
> col=1 col=2
>
>
>
> The same with frequencies.
> Any ideas on how to do this? I really want to avoid using
> excel for this.
*
* 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/