user2557039
user2557039

Reputation: 71

Type mismatch when trying to replace

I have a variable age_n . it is numeric (float). for exampel if i type count if age_n>65 If gives me 77.

So then if I type replace age_n = "0" if (age_n < "65") it says type mismatch. I have tried putting 65 without quotes and it still doesn't work.

Upvotes: 0

Views: 1005

Answers (1)

Another form to do it is

recode age_n (0/65=0 "0") (66/150=1 "over 65")

So you have a dummy with your requirement (from 0 to 65, values change to 0, appearing a "0" in the table; from 66 to 150, values change to 1, appearing this time "over 65" in the table). If you want to maintain values of age_n,

gen age_n2=age_n

and do the process with age_n2 instead of age_n.

Upvotes: 1

Related Questions