Dear STATA Forum,
Perhaps this is a relatively simple request and I am just not thinking about it in the correct way (most of my background is in R). The situation is as follows: there are 50 different variables, only some of which will need to be summed. For example, variables 1-10 might need to be summed. Then, the rest of the 50 variables, 11-50, will need to be summed as well.
I've already hard-coded it and obtained the correct values, but I was wondering if there might be a way to do this by manipulating varlists in STATA's programming language?
Let's say we have the following dataset:
And let's say we define the first varlist as follows:
The main question: Is there a way to store and then subtract from the default _all varlist the `temp' variables object? Apologies as that was a bit of a wordy statement.
Proposed pseudo-code:
The idea is to automatically define the complimentary temp2 object as all of the 50 variables minus those defined in the original temp object. Ideally both temp and temp2 would then automatically summed, although I was running into some issue doing sums of many variables (as indicated in earlier posts). The motivation behind this is to reduce the amount of user-inputs as possible as to avoid error (i.e. missing one variable out of 50 on the defined varlist, etc).
Thanks in advance!
Using STATA 15 MP.
Perhaps this is a relatively simple request and I am just not thinking about it in the correct way (most of my background is in R). The situation is as follows: there are 50 different variables, only some of which will need to be summed. For example, variables 1-10 might need to be summed. Then, the rest of the 50 variables, 11-50, will need to be summed as well.
I've already hard-coded it and obtained the correct values, but I was wondering if there might be a way to do this by manipulating varlists in STATA's programming language?
Let's say we have the following dataset:
Code:
clear input x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 1 2 3 4 5 6 7 8 9 10 4 5 6 7 8 9 10 1 2 3 end
Code:
varlist temp "x1 x2 x3"
Proposed pseudo-code:
Code:
local temp "x1 x2 x3" local temp2 _all-`temp' ///NB the '-' is interpreted as defining a range, need a workaround here... egen newvar1 = rowsum(`temp') egen newvar2 = rowsum(`temp2')
Thanks in advance!
Using STATA 15 MP.
Comment