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
Saving file name as local valueDear Stata Professionals I am currently suffering from saving file name as local value The code I …
Interpreting psgraph ftaer psmatch2I am employing propensity score matching using community-contributed psmatch2 command. To check for …
How do I replace a certain value across a dataset that has string as well as numeric variables?Hi everyone, I'm working with a dataset that has hundreds of variables, numeric as well as strings.…
Reshaping data to SUR formDear Everybody I'm trying to run a SUR regression and need to reshape my data accordingly. The data…
Identify All Values in One Variable that Satisfies a ConditionHi Statalist members, I encounter a difficulty in identifying values in one variable that satisfies…
Subscribe to:
Post Comments (Atom)
0 Response to Foreach loop across variables
Post a Comment