Question

I want to create a boxplot with whiskers. I want to compare several studies. For each study I have

  1. mean
  2. standard deviation sd
  3. name
  4. number of observations n

How can I do this in Stata 13 ?

Normally I would type

graph box var

but var is not the mean ........

Was it helpful?

Solution

If all you have from each study is the mean, standard deviation, and number of observations, you cannot possibly generate an accurate boxplot. However, you could assume the outcomes follow a particular distribution (e.g. normal distribution) and plot a boxplot of synthetically generated datasets using those summary statistics:

set.seed(144)
dat <- data.frame(study=c("A", "B", "C"), mean=c(1, 1.5, 1.2), sd=c(1, 2, 3),
                  n=c(40, 100, 12))
synthetic <- do.call(rbind, lapply(split(dat, seq(nrow(dat))), function(row) {
  data.frame(study=row$study, y=rnorm(row$n, row$mean, row$sd))
}))
boxplot(y~study, data=synthetic)

enter image description here

Just to reiterate, this is synthetic data being plotted, assuming a particular form of distribution for the study outcome. If you need to plot the study results, you'll need more information about each study -- the min and max, 25, 50, and 75 quartiles, and any outliers.

OTHER TIPS

Here's a way to do it in R. If you have access to the individual data points, you can do something like the following:

# Fake data
y = rnorm(100)

boxplot(y)

If you only have the summary statistics, you can manually change the values for the box-and-whisker statistics as follows:

plot1 = boxplot(y)
plot1$stats
           [,1]
[1,] -2.1433772
[2,] -0.5599737
[3,]  0.1944167
[4,]  0.6697005
[5,]  2.2113372

The above numbers are in order: lower whisker, lower box, midline, upper box, upper whisker. You can change those numbers to whatever values you have, as follows:

plot1$stats = c(-1.5, -1.2, 0.3, 1.2, 2.6) 

Or change single values as follows:

plot1$stats[2] = -1.2

Then redraw the plot:

boxplot(plot1$stats)

This is all very quick and dirty, but hopefully that will get you started.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top