As the title suggested, I would like to count the number of variables in multiple locals and meanwhile to compute the mean value of each group in Stata. For example,
I can use the following Stata code to compute total scores for each variable group, However, I don't know how to compute the mean value and don't want to do the hard coding
by counting the number of variables by hand.
*Compute total score of sub-scales.
local x1 ptgi_6 ptgi_8 ptgi_9 ptgi_15 ptgi_16 ptgi_20 ptgi_21
local x2 ptgi_3 ptgi_7 ptgi_11 ptgi_14 ptgi_17
local x3 ptgi_4 ptgi_10 ptgi_12 ptgi_19
local x4 ptgi_5 ptgi_18
local x5 ptgi_1 ptgi_2 ptgi_13
forvalue i = 1/5 {
egen ptgi_domain_`i'_sum = rowtotal( `x`i''), missing
}
Any help or hint is highly appreciated!
Related Posts with How to count the number of variables in multiple locals and meanwhile to compute the mean value of each group using for loop in Stata?
Regression with moderation in StataHello everybody, I am a bit unsure about the construction of my regression and need some help. I hav…
Why generating the variable in logarithm form change the sign of correlation and scatterplot?Hello, first of all I apologize for this simple question. I try to do some tests to find a relations…
keeping the last observation onlyI have different individuals and want to keep the last observation only. any commands? …
SUR Estimation - Equation residualsHi, I need to extract equationwise error terms of components of my SUR estimation. However by using…
e(clust#) not working in reghdfeHi, I ran into a problem where I do not know whether this is a bug or whether I am doing something w…
Subscribe to:
Post Comments (Atom)
0 Response to How to count the number of variables in multiple locals and meanwhile to compute the mean value of each group using for loop in Stata?
Post a Comment