Hi,
I have a variable "CaseDescription1". It's a string variable, with very long text description of a case. I want to create a new variable "RACF" if "CaseDescription1" contains any of the following terms: RACF, ACF, HLCNH, NH, nursing home, aged care facility it should be coded 1, if it doesn't contain those terms then 0.
So far I have tried (just with RACF, figured if I can't get it working with one term it's definitely not going to work with multiple). As you'll see it doesn't 'detect' RACF for any of the cases, even though it's definitely there for a few thousand:
gen RACF=strpos(CaseDescription1 ,"RACF")
.gen RACF_pt=1 if RACF>0
(2,858,239 missing values generated)
. tab RACF_pt
no observations
. drop RACF
. drop RACF_pt
. gen byte RACF = strmatch( CaseDescription1 , "*RACF*")
. tab RACF
RACF | Freq. Percent Cum.
------------+-----------------------------------
0 | 2,858,239 100.00 100.00
------------+-----------------------------------
Total | 2,858,239 100.00
. drop RACF
. gen byte RACF = 1 if strmatch( CaseDescription1 , "*RACF*")
(2,858,239 missing values generated)
. drop RACF
Thank you in advance.
Related Posts with Create binary variable if string contains any of the following
Random Effect Ordered Logit BayesianHi, I am trying to estimate the group residuals (RE) of the following simple model: HTML Code: Y…
Collecting marginal effects after probit estimation with a series of dummy variablesHi Statalist, I'm attempting to estimate a probit model on the likelihood of a patent being accepte…
How to plot the below graphs after quantile regression?Please could anyone tell how to plots the same graphs after quantile regression? I have tried to plo…
Creating Gini Coefficients from Categorical Income Data in 2000 US CensusHey everyone, This is my first post to Statalist. Please let me know if there is anything missing i…
efficiency analysis for multi output organisations (panel data)Dear all: I am new doing efficiency analysis with Stata. I want to estimate production and cost func…
Subscribe to:
Post Comments (Atom)
0 Response to Create binary variable if string contains any of the following
Post a Comment