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?
identify data pattern.Dear All, The question is from here (in Chinese). Suppose the data set is Code: * Example generated…
Rolling Regression with 24-60 months of observationsHi Everyone, I am trying to estimate rolling betas by using the past 24-60 months of data. I requir…
How to reduce the size of large data files in Stata?I have a dataset on "effects of marijuana on mental health" and it has 9 lac observations. Now I ass…
Export results for Markov-switching ARGood afternoon, I'm doing a few Markov-switching AR models and needed to store the results, prefera…
Main Effect and Interaction EffectHello, I am running a panel data analysis to examine the effect of Geographic Diversification (quad…
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