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: Table and derived values from entries in the table
From
Garry Anderson <[email protected]>
To
<[email protected]>
Subject
RE: st: Table and derived values from entries in the table
Date
Thu, 17 Mar 2011 23:07:52 +1100
Thank you Nick and Karl for your suggestion to use the collapse and tabdisp commands.
The marginals would be desirable, as per -help table- and the second table on page 1863 of the r.pdf manual.
Cheers, Garry
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Thursday, 17 March 2011 8:12 PM
To: [email protected]
Subject: Re: st: Table and derived values from entries in the table
I don't know of a short-cut that does what you want. But there is a mass of epidemiological add-ons that may do it. Otherwise you may just need to do the calculations step by step.
. collapse (sum) deaths (sum) pyears, by(agecat smokes)
. gen ratio = deaths / pyears
. tabdisp agecat smokes, cell(deaths pyears ratio)
I guess you want the marginals too.
Nick
On Thu, Mar 17, 2011 at 7:40 AM, Garry Anderson <[email protected]> wrote:
> I am enquiring how to include a value in a -table- that is a function
> of two other values in the table.
>
> An example follows in the -table- command. I wish to report in the
> third row of a cell the value in the first row of the cell divided by
> the value in the second row of the cell. For example, 2/18790 and
> 32/52407, etc. Please note I am using individual data rather than
> summed data, hence my use of the word sum in the contents list rather than mean.
>
> . use http://www.stata-press.com/data/r11/dollhill3, clear
>
> . list
>
> +-----------------------------------+
> | agecat smokes deaths pyears |
> |-----------------------------------|
> 1. | 1 1 32 52,407 |
> 2. | 2 1 104 43,248 |
> 3. | 3 1 206 28,612 |
> 4. | 4 1 186 12,663 |
> 5. | 5 1 102 5,317 |
> |-----------------------------------|
> 6. | 1 0 2 18,790 |
> 7. | 2 0 12 10,673 |
> 8. | 3 0 28 5,710 |
> 9. | 4 0 28 2,585 |
> 10. | 5 0 31 1,462 |
> +-----------------------------------+
>
> . table agecat smokes,con(sum deaths sum pyears) col row
>
> ----------------------------------
> | smokes
> agecat | 0 1 Total
> ----------+-----------------------
> 1 | 2 32 34
> | 18790 52407 71197
> |
> 2 | 12 104 116
> | 10673 43248 53921
> |
> 3 | 28 206 234
> | 5710 28612 34322
> |
> 4 | 28 186 214
> | 2585 12663 15248
> |
> 5 | 31 102 133
> | 1462 5317 6779
> |
> Total | 101 630 731
> | 39220 142247 181467
> ----------------------------------
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/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/statalist/faq
* http://www.ats.ucla.edu/stat/stata/