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: multiple CI/mean plots in one graphic
From
"Pieter-Jan" <[email protected]>
To
<[email protected]>
Subject
RE: st: multiple CI/mean plots in one graphic
Date
Fri, 29 Apr 2011 11:12:57 +0200
Nich,
Thanks a lot. This worked out great. Even on my dataset. I also used the
fpfit command which worked out as well. I can prepare my graph for our
manuscript. Once again thanks for this simple solution.
Regards,
Pieter-Jan van Ooij
-----Oorspronkelijk bericht-----
Van: [email protected]
[mailto:[email protected]] Namens Nick Cox
Verzonden: 29 april 2011 10:43
Aan: [email protected]
Onderwerp: Re: st: multiple CI/mean plots in one graphic
The commands are (on separate lines)
sysuse auto, clear
statsby mean=r(mean) ub=r(ub) lb=r(lb) , by(foreign rep78) : ci weight
separate mean, by(foreign) veryshortlabel
separate ub, by(foreign) veryshortlabel
separate lb, by(foreign) veryshortlabel
scatter mean0 mean1 rep78 || rcap ub0 lb0 rep78 || rcap ub1 lb1 rep78,
legend(order(1 2))
Note that the command -separate- is spelled in that way, but Stata
does for once indulge the spelling -seperate- when used for the
command. See
http://www.stata.com/statalist/archive/2008-11/msg00939.html
for the story.
On Fri, Apr 29, 2011 at 8:17 AM, Pieter-Jan <[email protected]> wrote:
> Dear Nick,
>
> Thanks for your reply. I tried to dally around with the auto database and
> use the commands your wrote down
>
> Sysuse auto, clear
> statsby mean=r(mean) ub=r(ub) lb=r(lb), by(foreign rep78): ci weight
> seperate mean, by(foreign) veryshortlabel seperate ub, by(foreign)
> veryshortlabel seperate lb, by(foreign) veryshortlabel scatter mean0 mean1
> rep78 || rcap ub0 lb0 rep78 || rcap ub1 lb1 rep78, legend(order(1 2))
>
> This gave me the error message
> invalid 'by'
> r(198);
>
> As I use the individual commands
> statsby mean=r(mean) ub=r(ub) lb=r(lb), by(foreign rep78): ci weight
> seperate mean
> (running ci on estimation sample)
> variable seperate not found
> an error occurred when statsby executed ci
> r(111);
>
> Tried to axecute without the separate mean commands
> statsby mean=r(mean) ub=r(ub) lb=r(lb), by(foreign rep78): ci weight
> (running ci on estimation sample)
>
> command: ci weight
> mean: r(mean)
> ub: r(ub)
> lb: r(lb)
> by: foreign rep78
>
> Statsby groups
> ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
> ........
>
> . by(foreign) veryshortlabel seperate ub
> : required
> r(100);
>
> I think I did something wrong regarding the commands but can not figure
out
> what. Is there a simple solution?
> Thanks
>
> Pieter-Jan van Ooij
>
>
> -----Oorspronkelijk bericht-----
> Van: [email protected]
> [mailto:[email protected]] Namens Nick Cox
> Verzonden: 28 april 2011 21:40
> Aan: [email protected]
> Onderwerp: Re: st: multiple CI/mean plots in one graphic
>
> -civplot- is a user-written plot from SSC written in 1999 for Stata 6.
> I am not surprised that it does not separate out different groups
> given a command
>
> . civplot variable1, by(time)
>
> as the command does not even mention -group-. Also, as -njc_stuff-
> (also SSC) documents, -civplot- is considered obsolete given -ciplot-
> (also SSC).
>
> But better than either is to do it yourself using the principles described
> in
>
> Cox, N.J. 2010. Speaking Stata: The statsby strategy. Stata Journal
> 10, 143-151.
> http://www.stata-journal.com/article.html?article=gr0045
>
> The following problem has essentially similar structure to yours and
> shows some technique
>
> sysuse auto, clear
> statsby mean=r(mean) ub=r(ub) lb=r(lb) , by(foreign rep78) : ci weight
> separate mean, by(foreign) veryshortlabel
> separate ub, by(foreign) veryshortlabel
> separate lb, by(foreign) veryshortlabel
> scatter mean0 mean1 rep78 || rcap ub0 lb0 rep78 || rcap ub1 lb1 rep78,
> legend(order(1 2))
>
> However, note that what you have done so far implies that separate
> days are independent, which may not be quite right!
>
> Nick
>
> On Thu, Apr 28, 2011 at 6:33 PM, Pieter-Jan <[email protected]> wrote:
>
>> Recently we performed a randomized crossover study in which we monitored
> the
>> lung function of a group of volunteers during three days. Day 1 was used
> to
>> determine baseline lung function whereas day 2 and 3 were used to monitor
>> lung function after inhaling either placebo (air) or active gas (oxygen)
>> under hyperbaric condition. During each measurement day lung function
was
>> measured 6 times. All variables and observations were put in a dataset
> which
>> initially had the following format:
>>
>> ID Group Time Variable1
etc
>> 1 0 0 6.19
>> 2 0 0 5.97
>> Etc
>>
>> ID exist of 13 persons
>> Group: 0 (baseline), 1 (placebo), 2 (active)
>> Time: 0, 2, 4, 8, 12, 22 hours after exposure
>>
>> To give the reader a good overview how f.e. variable 1 changes over time
>> within the 3 groups I want to plot the CI and mean of each group on each
>> time point in one graphic. I tried civplot
>>
>> Civplot variable1, by(time)
>>
>> But that gives me no separate plots of the three groups.
>>
>> I tried to change the dataset by deleting the group variable and changing
>> the Variable1 etc as follows
>>
>> ID Time Variable1_baseline Variable1_placebo
>> Variable1_active etc
>> 1 0 6.19 6.01
>> 6.11
>> 2 0 5.97 6.05
>> 5.91
>>
>> Civplot variable1_baseline, by(time)
>>
>> This allows me only 1 civplot for each variable but just like the first
>> attempt this gave me only 1 plot per graphic. I tried also twoway
>>
>> Twoway (scatter variable1_baseline time) (fpfit variable1_baseline time)
>> (scatter variable1_placebo time) (fpfit variable1_placebo time) (scatter
>> variable1_active time) (fpfit variable1_active time)
>>
>> And this gives the possibilities of putting multiple plots in one graphic
>> but specially the scatter makes it cluttered. A simple CI/mean would
>> counteract this.
>>
>> Is there a possibility in Stata of putting multiple CI/mean plots into
one
>> graphic? Maybe the answer speaks for itself but I am rather new into
Stata
>> that's why I asking this question.
*
* 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/