I am a Salesforce admin and a Stata novice. A solution to my problem would help working with Salesforce multi-select fields and any similar strings containing multiple values.
I put together an example to explain my problem better:
record number - value - result I need to get and keep
1 - a,b,c - book
2 - c,b,d - book
3 - b,c - magazine
4 - c - newspaper
When I used the code below, I did not get the correct count, since all values were counted every time they appeared in each string:
replace value = "book" if strpos(value, "a") | if strpos(value, "d")
replace value = "magazine" if strpos(value, "b")
replace value = "newspaper" if strpos(value, "c")
If I drop each value after it gets counted, I get the correct counts for all observations, but almost the whole dataset gets deleted!
The preserve and restore commands do not work, any changes made to the data after preserve get undone by restore.
Seems like some kind of a "for" loop would work for this task if I could loop through the data without deleting them, but I don't know how to write it.
Your help would be greatly appreciated!
Dina
I put together an example to explain my problem better:
record number - value - result I need to get and keep
1 - a,b,c - book
2 - c,b,d - book
3 - b,c - magazine
4 - c - newspaper
When I used the code below, I did not get the correct count, since all values were counted every time they appeared in each string:
replace value = "book" if strpos(value, "a") | if strpos(value, "d")
replace value = "magazine" if strpos(value, "b")
replace value = "newspaper" if strpos(value, "c")
If I drop each value after it gets counted, I get the correct counts for all observations, but almost the whole dataset gets deleted!
The preserve and restore commands do not work, any changes made to the data after preserve get undone by restore.
Seems like some kind of a "for" loop would work for this task if I could loop through the data without deleting them, but I don't know how to write it.
Your help would be greatly appreciated!
Dina
Comment