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.
Calculate weight for repeated cross-sectional data collected weekly since May 2020Hi Could you please suggest how do I calculate weight for the data considered as repeated cross-sect…
Help!Can't open data in STATADear Statalister, I would like to ask why I cannot open data that download as STATA v14+ file.dta f…
How can I 'find' a specific word across multiple variable strings?I'm using Stata 14.2 on Windows. I have a dataset which is STI testing data, each line is a test res…
Query of small sampleDear Statalist, I would like to get your advice about a stata command. I prefer to generate a small …
negative and insignificant Error correction coefficienti am working on panel data( (21) cross section data 1990-2019) dealing with symmetric and asymmetric…
Subscribe to:
Post Comments (Atom)
0 Response to Stata 13. Counting variable on loop.
Post a Comment