Hello,

I'm using tabstat to generate weighted standard deviations, by year, for two variables in a panel dataset. What I would like is to add these to my dataset as new variables. I've got some of the way here, but cannot quite get it to work.

First, I generate the statistics, as follows:
Code:
tabstat lpcpi lpcpinf [aw=pop], by(year) stat(sd) columns(statistics) save
I think this gives me the right output. Doing a little digging, I found code that puts the total standard deviations in a new variable, as follows:


Code:
        matrix stats=r(StatTotal)
        svmat stats, name(var)   
    svmat stats, name(var)

But of course this is just the sd for all observations, not each year's sd in an observation pertaining to that year.

Any ideas?

Thanks
Tom