In my dataset, there are two fields: pmid (long) and abs (string).
I'm looking for co-occurrence of pairs of string words within the -abs- field, and when those conditions are met, want to generate a new y/n indicator variable.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input strL abs long pmid "...Experimental demonstrated inhibition..." 9923456 "...Control resulted in expression..." 8767722 end
The word pairs in the -abs- field for which I'll be searching consist of terms for:
experimental group: in this example, "Experimental" or "Control", and
biological effect: in this example, "inhibition" or "expression"
The reasons I'm thinking using a -forvalues- loop would be fruitful, are:
1. I have a list of Experimental Group terms, for which I'll be searching the -abs- field.
2. I have a list of Biological Effect terms, for which I'll also be searching the -abs- field.
3. I want to write a loop that says "find all records in which the -abs- field contains specified Experimental Group AND Biological Effect term pairs, and then generate a y/n indicator variable identifying records where each word pair was found.
In this code example below, not using loops of forvalues, I've written code that does one-at-a-time search and variable generation:
Code:
l pmid if (index(abs, "Experimental") | index(abs, "Control")) & (index(abs, "inhibition") | index(abs, "expression")), noo clean gen ExperimentalInhibition = 1 if index(abs, "Experimental") & index(abs, "inhibition") gen ControlExpression = 1 if index(abs, "Control") & index(abs, "expression") list
Michael
0 Response to Using loops to search string vars, then generate new indicator variables
Post a Comment