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.
Bug in graph bar(?)Hello everyone, I am trying, for an hour, to do a very simple bar graph in principle, but stata some…
How to refer to (and select) other variable within observation conditional on dummy being 1?I am stuck on a very particular problem and I am sure there needs to be a way to solve it. The data…
Requesting help on data structure, routine and graphHello all, I'm working with monthly rainfall data over a 40 year period and the goal is to see if th…
Calculating distance between inventors, how to perform per patent?Hi all! I have a question regarding how to calculate average distance between inventors per patent.…
Generates averages for partial observationsHi everyone! My dataset is composed of 4122 observations: 83 cities and for each observation to 190…
Subscribe to:
Post Comments (Atom)
0 Response to Stata 13. Counting variable on loop.
Post a Comment