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?
Combining meglm and svy: error messageOur goal is to build a three-level hierarchical linear model based on complex survey design in Stata…
Propensity score matching and outcome variableDear all, I am trying to create a control group using Propensity score matching. The idea is to sel…
2x7 table differencesSo I have 2 independent variables and 1 dependent category with 7 variables. Fishers exact tells me …
xtmixed difference between main model and postestimation (pwcompare) results (with and without interaction effect)Hi there - sorry if this is a very silly question, but I was a little confused. Simplifed code and m…
Tabulating and dropping grouped dataHi, I have a dataset based on a survey where each individual is given a unique id and has several r…
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