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
Negative Binomial Regression & NonlinearityNegative binomial regression - which relies on the log-link function - models the expected value of …
Command for fixed effects ordered logitIs there a user-developed Stata command for fixed effects ordered logit? I know that xtologit does n…
Delete Observations that have no partners in panel dataHello.. i am new in here i got some problem in using STATA i am trying to make panel data but not…
Confusion About Reduced-Form EstimationI'm using Stata 14 for Mac and I'm exploring a data set. It was going well but I've hit a wall. The…
HotDeck results not reproducibleHi everyone, I'm imputing data using HotDeck. gen income1 = income if treat == 0 hotdeck income1, …
Subscribe to:
Post Comments (Atom)
0 Response to Foreach loop across variables
Post a Comment