Dear all,
I'm having problems trying to generate a variable of count from a local and a loop. I need to count the number of times a subject has chosen number 2 across 6 variables. Then, to generate a variable with the number of times the option 2 has been selected.
Here my code:
(id: id of subject)
gen count2=.
local var var1 var2 var3 var4 var5 var6
foreach x of local var{
replace count2=count(`x'==2), by id
}
The result says: "error" unknown function count"
Any suggestions on this. I'd appreciate very much.
Best
Related Posts with Stata 13. Counting variable on loop.
Present 3 regression models in a single tableI have done three regressions in STATA. All variables are same, but in the 'country_name' variable (…
Truncate a number to two decimalsHi, I have a doubt. I have a variable named "score" (float) as showed below and I want to truncate i…
Generating a variableI have a variable that measure money (M) whats the command to generate a new variable "m.lower" whic…
Interpreting the r and adjusted r square value in an arima modelHello, i have been working on some time series data for the last couple of days which has required t…
Matching two samples by the same year/industry/provinceDear Stata experts, I have a sample of firms committed fraud. It has 1,700 observations. The format…
Subscribe to:
Post Comments (Atom)
0 Response to Stata 13. Counting variable on loop.
Post a Comment