Hi all,
I'm having some issues with counting the number of elements in a local. Take the examples below:
Code:
local list "item one" "item two" "item three" "item four"
foreach l of local list{
di "`l'"
}
item
one
item two
item three
item four
It appears Stata is viewing "item one" in the local as two separate items and then all subsequent items as single items. I want them all to be viewed as single items (so the local above contains four not five). Wrapping each item in `' quotes and the entire list in "" quotes solves how they are displayed. E.g.:
Code:
local list "`"item one"' `"item two"' `"item three"' `"item four"'"
foreach l of local list{
di "`l'"
}
item one
item two
item three
item four
But then if I use the word count function it tells me there are 5 items in the local (even though it's obviously just displayed four). Does anyone know how I can correct this, or what's going on?
Code:
local count: word count of `list'
di "`count'"
5
0 Response to Local behaviour I don't understand
Post a Comment