Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: How to easily insert all tab statistics into matrix for export
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: How to easily insert all tab statistics into matrix for export
Date
Wed, 17 Apr 2013 20:20:24 +0100
Stephen is evidently using the -row()- option (not command) of
-tabulate-. How else can these calculations be done?
In addition to other good advice: Mata is your friend.
. sysuse auto
(1978 Automobile Data)
. tab foreign rep78 , matcell(foo)
| Repair Record 1978
Car type | 1 2 3 4 5 | Total
-----------+-------------------------------------------------------+----------
Domestic | 2 8 27 9 2 | 48
Foreign | 0 0 3 9 9 | 21
-----------+-------------------------------------------------------+----------
Total | 2 8 30 18 11 | 69
. mat li foo
foo[2,5]
c1 c2 c3 c4 c5
r1 2 8 27 9 2
r2 0 0 3 9 9
. mata :
------------------------------------------------- mata (type end to
exit) ---------------
: foo = st_matrix("foo")
: 100 * foo :/ rowsum(foo)
1 2 3 4 5
+-----------------------------------------------------------------------+
1 | 4.166666667 16.66666667 56.25 18.75 4.166666667 |
2 | 0 0 14.28571429 42.85714286 42.85714286 |
+-----------------------------------------------------------------------+
Nick
[email protected]
On 17 April 2013 19:27, Stephen Cranney <[email protected]> wrote:
> Hi all,
>
> I'm trying to insert all of the statistics I derive from the tab
> command into a matrix so that I can use the frmttable command to
> automate the frequency table generation. Specifically, I'm using the
> row percentage command, but the row statistics are not collected in
> the matrix. So I'm wondering if there's a way to automatically place
> the row statistics in the matrix or, if that's not an option, if
> there's an efficient way to calculate a percentage row beneath each
> row in the matrix that doesn't require customizing the dimensions for
> each respective frequency table. I've done way too many of these
> tables by hand in excel. Surely there has to be a way to automate
> this.
>
> Thanks in advance,
>
> Stephen
>
>
> --
> Stephen Cranney
>
> PhD Student
> Graduate Group in Demography
> University of Pennsylvania
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/