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: Collecting ttest results using parmby, factext, metaparm
From
Roger Newson <[email protected]>
To
[email protected]
Subject
Re: st: Collecting ttest results using parmby, factext, metaparm
Date
Tue, 13 Sep 2011 13:09:30 +0100
You do not state how your program is failing. However, when I run a
version of your example in the -auto- data, the problem seems to be that
you have called -factext- in the original dataset, and not in the
-parmby- resultsset.
A version of your -auto- example that works for me (using the SSC
packages -sencode- and -keyby-) is as follows:
**** BEGINNING OF EXAMPLE - CUT HERE ****
#delim ;
version 12.0;
sysuse auto, clear;
global tflist "";
global modseq=0;
tempfile temp1;
descsave foreign, do(`"`temp1'"', replace);
foreach X of var weight length {;
local Xlab: var lab `X';
global modseq=$modseq+1;
tempfile tf$modseq;
ttest `X', by(foreign);
parmby "xi, noomit: regress `X' i.foreign, noconst", label
format(estimate min* max* %8.2f p %-8.2g) idstr("`Xlab'")
saving(`"`tf$modseq'"',replace) flist(tflist);
};
dsconcat $tflist;
sencode idstr, gene(outcome);
factext, do(`"`temp1'"');
drop idstr label;
keyby outcome foreign;
desc;
list, abbr(32) noobs sepby(outcome);
metaparm [iwei=!foreign-foreign], dfcombine(constant) by(outcome) list(,
abbr(32) sepby(outcome));
**** END OF EXAMPLE - CUT HERE ****
This does what I think David wants, ie equal-variance t-tests comparing
US and non-US cars regarding weight and length. The -sencode- command is
a super version of -encode- which encodes sequentially by default, and
the -keyby- package is a version of -sort- that checks that the sort key
identifies observations uniquely.
If David has Stata Version 12, then David should probably be using
factor varlists instead of -xi-, and -fvregen- instead of -factext-, and
might also use official Stata's -append- instead of -dsconcat-.
As in the following version:
**** BEGINNING OF EXAMPLE - CUT HERE ****
#delim ;
version 12.0;
sysuse auto, clear;
global tflist "";
global modseq=0;
tempfile temp1;
descsave foreign, do(`"`temp1'"', replace);
foreach X of var weight length {;
local Xlab: var lab `X';
global modseq=$modseq+1;
tempfile tf$modseq;
ttest `X', by(foreign);
parmby "regress `X' ibn.foreign, noconst",
format(estimate min* max* %8.2f p %-8.2g) idstr("`Xlab'")
saving(`"`tf$modseq'"',replace) flist(tflist);
};
clear;
append using $tflist;
sencode idstr, gene(outcome);
fvregen, do(`"`temp1'"');
drop idstr;
keyby outcome foreign;
desc;
list, abbr(32) noobs sepby(outcome);
metaparm [iwei=!foreign-foreign], dfcombine(constant) by(outcome) list(,
abbr(32) sepby(outcome));
**** END OF EXAMPLE - CUT HERE ****
Note that, if you use -fvregen-, then you no longer need either -xi- or
the -label- option of -parmby-, as the factor values are extracted from
the variable -parm-.
I hope this helps. Let me know if you have any further queries.
Best wishes
Roger
Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected]
Web page: http://www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/popgenetics/reph/
Opinions expressed are those of the author, not of the institution.
On 13/09/2011 09:46, David Scharff wrote:
Dear all
I need to collect the results of a series of ttests (equal variances),
store them in a file together with their p-values. In a second step, I
want to plot the means of the variables with CI’s using ECLplot. I’m
using Roger Newson’s parmby, factext and metaparm commands. This is my
code. I cannot manage to get factext working it seems, but I do not
figure out where my mistake is. As is obvious, I'm not very
experienced in programming Stata. (I use Stata 12 if this is
relevant).
global tflist ""
global modseq=0
foreach X of var sem_a sem_b {
global modseq=$modseq+1
tempfile tf$modseq temp1
descsave, do(`temp1', replace)
ttest `X', by(case)
parmby "xi, noomit: regress `X' i.case, noconst", label
format(estimate min* max* %8.2f p %-8.2g) idn($modseq)
saving(`tf$modseq',replace) flist(tflist)
factext, do(`temp1')
metaparm [iwei=!case-case], dfcombine(constant) saving(`tf$modseq',replace)
}
dsconcat $tflist
The same, adapted to the auto data for easier inspection:
sysuse auto, clear
global tflist ""
global modseq=0
foreach X of var weight length {
global modseq=$modseq+1
tempfile tf$modseq temp1
descsave, do(`temp1', replace)
ttest `X', by(foreign)
parmby "xi, noomit: regress `X' i.foreign, noconst", label
format(estimate min* max* %8.2f p %-8.2g) idn($modseq)
saving(`tf$modseq',replace) flist(tflist)
factext, do(`temp1')
metaparm [iwei=!foreign-foreign], dfcombine(constant)
saving(`tf$modseq',replace)
}
dsconcat $tflist
Any help is greatly appreciated - I have spent hours finding my mistake now...
Many thanks in advance!!
David
*
* 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/