3

I want to calculate panel descriptive statistics for my variables analogously to how Stata provides them using the "xtsum" function. I am able to compute almost everything (overall/within sd, mean, min, max) but I cannot seem to find a reliable source with the formula to compute the between sd. Anybody that knows the formula/has a reliable source?

So far I have used the formula from this thread Between/within standard deviations in R. But I'm unsure whether this formula is correct.

Marco
  • 2,368
  • 6
  • 22
  • 48

1 Answers1

0

In this post: xtsum command for R? you find an R implementation of the entire xtsum command. You can pick the line for between variation. It's hidden a little bit.

I used some easy example data, and it perfectly replicates the results from Stata:

paneldata = data.frame(id=c(1,1,1,2,2,2,3,3,3), time=seq(1:3), variable=c(9,10,11,20,20,20,25,30,35))
XTSUM(paneldata, varname = variable, unit=id)

R output with "XTSUM":

enter image description here

Stata output:

enter image description here

Be aware of some differences in the within-formula which is adjusted in Stata. You also find valuable information in this post:

http://stephenporter.org/files/xtsum_handout.pdf

Example data comes from here:

http://rizaudinsahlan.blogspot.com/2016/06/within-and-between-variation-in-panel.html

Marco
  • 2,368
  • 6
  • 22
  • 48