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.
Use of Year Dummies in Fixed Effects ModelGood Afternoon, I am currently undertaking a piece of research in which I require a fixed-effects m…
Loading CSV vs Excel files in to Stata - risksI have a large patient level covid-19 test dataset which is exceeding 400MBs. It is in excel format …
Delete rows based on condition (panel data)Hi Stata forum, I would like to delete rows in my panel data based on a condition. The rows with mi…
Replace with long list of values Hello to everyone, I am trying to create a dummy variable for some countries that are federal state…
Lincom commandHi, I wanted to know if someone can help me. I am trying to ascertain the change in the sensitivity…
Subscribe to:
Post Comments (Atom)
0 Response to Stata 13. Counting variable on loop.
Post a Comment