[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
RE: st: Using wildcards with string values of a variable
needs to be followed immediately by an equals sign.
In your case, your criterion seems to be that
the first three characters are "fill". If so,
the whole apparatus of wildcards, matching,
regular expressions and what have you can be
avoided by using -substr()-.
gen id2 = id
replace id2 = "filled" if substr(id,1,3) == "fill"
gen id2 = cond(substr(id,1,3) == "fill", "filled", id)
> See this function from Stata help
> strmatch(s1,s2) evaluates to 1 if s1 matches the pattern
> s2; otherwise,
> it returns 0.
> The new dataset contains the variable 'id' which
> contains string values "fill1", "fill 2" etc and "study 1",
> "study 2" etc. I have tried the following commands:
> gen id2=id
> replace id2 "filled" if id=="fill*"
> which didn't work. I cannot find any reference of a
> wildcard being used
> in such a situation, is it possible? I'm sure there is a
> very simple
> solution to my problem so I apologise in advance!
* For searches and help try: