Bookmark and Share

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: RE: RE: rearrange table#2 -add variables


From   Nikolaos Pandis <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: RE: RE: rearrange table#2 -add variables
Date   Fri, 10 Feb 2012 04:30:54 -0800 (PST)

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.

Thank you,

Nick


Nick



----- Original Message -----
From: Nick Cox <[email protected]>
To: "'[email protected]'" <[email protected]>
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 
[email protected] 

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 
[email protected] 

From: [email protected] [mailto:[email protected]] 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?searchhttp://www.stata.com/support/statalist/faqhttp://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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index