Hi,
I have over a thousand dummy variables for 30,000 data entries. I want to find a way to count the number of times each one of those variables appears as 1 using a foreach 'variable' loop command. Would be helpful if there was another command. Here is the command I used:
After generating a new variable "fortier" to count the number of times a variable appears as '1', I then tried to replace it with a loop in the following way, where Stern and Pierneef are 2 out of the 1000 dummy variables.
foreach `var' of varlist Stern Pierneef {
replace fortier = count(`var') if `var'==1
}
Related Posts with Foreach loop across variables
Rename variables to remove part of the textDear Statalists, I have the following variables and would like to rename them to remove untitled###…
Question spmapHi, I have a question about spmap. I'm just a beginner with STATA and I want to know how to use spm…
ivreg, ivprobit and biprobit which one to use? (any theoretical reasoning?)As I do not have any econometric background I find it difficult to understand which one to use when …
BetaregHi all, I have a propotion dependent variable that’s greater than zero and less then one. The mean …
Adding options to a package (.ado)Hi everyone, I have written a code to run the LFK index (Int J Evid Based Healthc. 2018 Dec;16(4):1…
Subscribe to:
Post Comments (Atom)
0 Response to Foreach loop across variables
Post a Comment