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]

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 iassume i would adapt the code you had already sent. The addedproblem was that if there were more than 1 3-level (same levels forall) variables like below:level1 level2 level3 var1 freq freq freq var2 freq ... ... var3 freq ... freqI am reporting reporting quality features from RCTs and the scoringhas 3-levels (1=no description, 2=inadequate, 3=adequate)The scoring is applied to several items See part of table belowdone 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 variablesI am not very clear on quite what you want to tabulate, but inprinciple the strategy can be the same. -statsby- can leavefrequencies in its wake too.-tabw- is from STB-25. Please remember to explain where user-writtenprograms you refer to come from. This is a longstanding requestexplicit in the FAQ. -tabw- is fine for what it does, but it is evenmore of a dead end for anything not supported by Stata's existingtable commands.A similar comment applies to -tabm- from -tab_chi- (SSC).It's only occasionally that any commands have hidden options forextra things.On complication: Yes, I agree. We all want a really simple tablecommand that produces any table we can think of, a desire easy tostate but hard to satisfy.Nick n.j.cox@durham.ac.ukFrom: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nikolaos PandisDear 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 additionalvariables like below. I assume I can follow the icluded code to getthe frequencies instead om mean, sd and cis, but how could i add theother variables?level1 level2 level3 var1 var2 var3I have found the user written command -tabw- and it would work if icould somehow supress the missing values or select only to showfrequencies 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, clearstatsby N=r(N) se=r(se) mean=r(mean) ub=r(ub) lb=r(lb), by(foreign) : ci mpggen 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 toa dataset of results -- some people say resultsset -- for maximumflexibility.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 alsoSJ-10-1 gr0045 . . . . . . . . . . . . . Speaking Stata: Thestatsby strategy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .N. J. CoxQ1/10 SJ 10(1):143--151 (nocommands)demonstrates the use of statsby to prepare a reduced dataset for subsequent graphing Nick n.j.cox@durham.ac.ukFrom: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nikolaos PandisI 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/

**References**:**st: rearrange table***From:*Nikolaos Pandis <npandis@yahoo.com>

**st: RE: rearrange table***From:*Nick Cox <n.j.cox@durham.ac.uk>

**st: RE: RE: rearrange table***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: RE: RE: rearrange table#2 -add variables***From:*Nikolaos Pandis <npandis@yahoo.com>

**RE: st: RE: RE: rearrange table#2 -add variables***From:*Nick Cox <n.j.cox@durham.ac.uk>

**Re: st: RE: RE: rearrange table#2 -add variables***From:*Nikolaos Pandis <npandis@yahoo.com>

- Prev by Date:
**RE: st: using post stratification weights** - Next by Date:
**Re: st: why Margins gives "not estimable" ?** - Previous by thread:
**Re: st: RE: RE: rearrange table#2 -add variables** - Next by thread:
**st: Computing the Gini or another inequality coefficient from a limited number of data points** - Index(es):