… and add columns for differences and t-statistics.
I learned how to make a quantile by quantile table of means and how to add a column/row of differences here (thanks to @lejohn).
Now instead of each row as one quantile of one variable, I would like each row to be a different variable and each cell would be the mean value for each variable for the individuals that fall in each column for the quantile of a given variable.
I can calculate the cell entries easily with tabstat, but I would like the variables in the rows and the quantiles in the columns (tabstat produces the transpose). I would also like the ability to difference columns (as in my first question) and calculate t-statistics for the cell differences.
I feel like the intermediate step is to reshape to long data with three columns: id (here acc_d), variable name, and variable value. But I can’t figure out how to do this and I may be stuck in an R paradigm.
Here is an example of the type table I would like to make

and here is some code with which I have been (unsuccesfully) tinkering
* generate data
clear
set obs 2000
generate acc = rnormal()
generate r1 = rnormal()
generate sar1 = rnormal()
generate arbrisk = rnormal()
* generate quantiles for for a and b
xtile acc_d = acc, nquantiles(10)
* form table (at least my attempts)
* w/ tabstat (but transposed and can't manipulate columns)
tabstat acc r1 sar1 arbrisk, stat(mean) by(acc_d) nototal
* my attempts to reshape fail, but I would want something like to following to use tabulate
* acc_d variable value
* 1 acc 0.01
* 1 r1 1.03
* 1 sar1 -0.03
* 1 arbrisk 0.05
* 2 acc 1.01
* 2 r1 2.03
* 2 sar1 0.03
* 2 arbrisk 1.05
Thanks!
Here I would proceed a bit differently. I would first of all gather the information required to compute the difference and the t statistic
Then I would proceed by collapsing and transposing the data
In a last step, I would add the difference and the t statistic:
And finally print the results:
Hope this helps.