Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: RE: rearrange table#2 -add variables


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: RE: RE: rearrange table#2 -add variables
Date   Sat, 11 Feb 2012 17:19:06 +0000

Try -tabm- from -tab_chi- (SSC).

Nick

On 11 Feb 2012, at 14:29, Nikolaos Pandis <npandis@yahoo.com> wrote:

Nick,

Thank you for the postings.
The second question was similar but only needed frequencies so i assume i would adapt the code you had already sent. The added problem was that if there were more than 1 3-level (same levels for all) variables like below:

     level1 level2 level3
var1  freq   freq   freq
var2  freq   ...    ...
var3  freq  ...      freq

I am reporting reporting quality features from RCTs and the scoring has 3-levels (1=no description, 2=inadequate, 3=adequate) The scoring is applied to several items See part of table below done manually:


Item No Description
% Inadequate
% Adequate
%
1.title 45.3 39.3 15.4
2.structured 14.5 0.0 85.5
3.trial design 22.2 59.8 18.0
4.participants 9.4 35.9 54.7
5.interventions 0.0 2.6 97.4
6. objective 1.7 5.1 93.
.....................

I will make sure next time to quote accurately user written commands.

Many thanks.

Nick


From: Nick Cox <n.j.cox@durham.ac.uk>
To: "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Sent: Friday, February 10, 2012 3:19 PM
Subject: RE: st: RE: RE: rearrange table#2 -add variables

I am not very clear on quite what you want to tabulate, but in principle the strategy can be the same. -statsby- can leave frequencies in its wake too.

-tabw- is from STB-25. Please remember to explain where user-written programs you refer to come from. This is a longstanding request explicit in the FAQ. -tabw- is fine for what it does, but it is even more of a dead end for anything not supported by Stata's existing table commands.

A similar comment applies to -tabm- from -tab_chi- (SSC).

It's only occasionally that any commands have hidden options for extra things.

On complication: Yes, I agree. We all want a really simple table command that produces any table we can think of, a desire easy to state but hard to satisfy.

Nick
n.j.cox@durham.ac.uk


From: owner-statalist@hsphsun2.harvard.edu [mailto:owner- statalist@hsphsun2.harvard.edu] On Behalf Of Nikolaos Pandis

Dear Nick and Phil,

Many thanks for your help.
I did try it and it worked!
It does seem like a complicated process!

Extending the previous question.

What if I would like to get only frequencies but add additional variables like below. I assume I can follow the icluded code to get the frequencies instead om mean, sd and cis, but how could i add the other variables?

         level1   level2  level3
var1
var2
var3

I have found the user written command -tabw- and it would work if i could somehow supress the missing values or select only to show frequencies of let's say only 1-3 instead of from 1-9 etc.

----- Original Message -----
From: Nick Cox <n.j.cox@durham.ac.uk>
To: "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Cc:
Sent: Friday, February 10, 2012 2:06 PM
Subject: st: RE: RE: rearrange table

sysuse auto, clear
statsby N=r(N) se=r(se) mean=r(mean) ub=r(ub) lb=r(lb), by (foreign) : ci mpg
gen sd = se * sqrt(N)
drop se N
rename (sd mean lb  ub) (statsd statmean statlb statub)
reshape long stat, i(foreign) string
label def which 1 mean 2 sd 3 lb 4 ub
encode _j , label(which) gen(which)
label def which 3 "95% limit: lower" 4 "upper", modify
tabdisp which foreign, c(stat) format(%3.2f)

Nick
n.j.cox@durham.ac.uk

Nick Cox

In terms of -table-, the answers are

1. I don't think you can do this.

2. -table- has its own option -format()-: see the help.

3. I don't think you can do this.

In terms of strategy, just as in another thread: reduce your data to a dataset of results -- some people say resultsset -- for maximum flexibility.

Here -statsby- is very useful.

One approach:

. sysuse auto, clear
(1978 Automobile Data)

. statsby mean=r(mean) ub=r(ub) lb=r(lb), by(foreign) : ci mpg
(running ci on estimation sample)

      command:  ci mpg
        mean:  r(mean)
          ub:  r(ub)
          lb:  r(lb)
          by:  foreign

Statsby groups
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..

. save bystat, replace
file bystat.dta saved

. sysuse auto, clear
(1978 Automobile Data)

. statsby sd=r(sd), by(foreign)  : su mpg
(running summarize on estimation sample)

      command:  summarize mpg
          sd:  r(sd)
          by:  foreign

Statsby groups
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..

. merge 1:1 foreign using bystat
(label origin already defined)

    Result                          # of obs.
    -----------------------------------------
    not matched                            0
    matched                                2  (_merge==3)
    -----------------------------------------

. drop _merge

. rename (sd mean lb  ub) (statsd statmean statlb statub)

. reshape long stat, i(foreign) string
(note: j = lb mean sd ub)

Data                              wide  ->  long
--- --- --- --------------------------------------------------------------------
Number of obs.                        2  ->      8
Number of variables                  5  ->      3
j variable (4 values)                    ->  _j
xij variables:
            statlb statmean ... statub  ->  stat
--- --- --- --------------------------------------------------------------------

. label def which 1 mean 2 sd 3 lb 4 ub

. encode _j , label(which) gen(which)

. label def which 3 "95% limit: lower" 4 "upper", modify

. tabdisp which foreign, c(stat) format(%3.2f)

-------------------------------------
                |      Car type
          which | Domestic  Foreign
-----------------+-------------------
            mean |    19.83    24.77
              sd |    4.74      6.61
95% limit: lower |    18.51    21.84
          upper |    21.15    27.70
-------------------------------------

Here's the code in one:

sysuse auto, clear
statsby mean=r(mean) ub=r(ub) lb=r(lb), by(foreign) : ci mpg
save bystat, replace
sysuse auto, clear
statsby sd=r(sd), by(foreign)  : su mpg
merge 1:1 foreign using bystat
drop _merge
rename (sd mean lb  ub) (statsd statmean statlb statub)
reshape long stat, i(foreign) string
label def which 1 mean 2 sd 3 lb 4 ub
encode _j , label(which) gen(which)
label def which 3 "95% limit: lower" 4 "upper", modify
tabdisp which foreign, c(stat) format(%3.2f)

On -statsby- see also

SJ-10-1 gr0045 . . . . . . . . . . . . . Speaking Stata: The statsby strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox Q1/10 SJ 10(1):143--151 (no commands)
        demonstrates the use of statsby to prepare a reduced
        dataset for subsequent graphing






Nick
n.j.cox@durham.ac.uk

From: owner-statalist@hsphsun2.harvard.edu [mailto:owner- statalist@hsphsun2.harvard.edu] On Behalf Of Nikolaos Pandis

I am running the following commands:

. format percent %4.2f

. table title,contents(mean percent sd percent )
---------------------------------------------
         title | mean(percent)    sd(percent)
---------------+-----------------------------
No description |         57.74       3.619958
    Inadequate |         61.11       5.202971
      Adequate |         65.50       5.015084
---------------------------------------------

I would like to ask:
1. How can I place the title levels(no description, inadequate, adequate) as columns and the summary stats as rows.
2. How could I reduce to 2 the decimal points for sd.

3. Is there a way to add 95% CIs?

*
*  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/

*
*  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/
*
*   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/


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