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?
What does "unrestricted treatment effect heterogeneity" mean?Borusyak, 2021 has a sentence We show that this estimator takes a particularly transparent form…
Why homogeneous treatment assumption leads to "spurious identification of long-run treatment" in staggered DiD?Borusyak, 2021 has a sentence Third, in dynamic specifications, implicit assumptions about trea…
mestreg - Incorporating Variance covariance structureGreetings!! I'm John, currently working on multilevel survival analysis using mestreg command.. I wa…
How to perform CS-ARDL?Hello all, I want to apply CS-ARDL to my model but as I am new to the field and STATA I could not f…
95% confidence intervals around proportions on line graph – usefulness?Hi all, I’m using Stata 15. I’m doing an analysis of applicants for grants. I have a graph showing,…
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