Hi, I've been going around in more circles trying to clean up some data and wondered if anyone had any suggestions:
I've got a dataset which referred to expenses so our question "how much did the item cost you' has been answered with 2.4 4.6 2.3 etc which is fine - what makes this mroe complicated is that some people have put text values in - some imply a value e.g. "got it for free" or "monthly subscription" and some missing values e.g. "not entered". This variable is a string variable called Q1.
What I thought was a sensible idea was to create a new variable where I could enter values for the text:
generate totalcost = ".a" if Q1 == "not entered"
replace totalcost = 0 if Q1 == "got it for free"
replace totalcost = 5 if Q 1 == "monthly subscription"
but what I haven't managed to do is keep the same value for totalcost if Q1 already = a numeric value.
then I thought that away around this would be to generate total cost = Q1
then
replace totalcost = 0 if Q1 == "got it for free"
replace totalcost = 5 if Q 1 == "monthly subscription"
replace totalcost = ".a" if Q1 == "not entered"
but I'm getting 'Type Mismatch' I'm assuming because the original is a string - is there a way around this?
Any thoughts much appreciated.
I've got a dataset which referred to expenses so our question "how much did the item cost you' has been answered with 2.4 4.6 2.3 etc which is fine - what makes this mroe complicated is that some people have put text values in - some imply a value e.g. "got it for free" or "monthly subscription" and some missing values e.g. "not entered". This variable is a string variable called Q1.
What I thought was a sensible idea was to create a new variable where I could enter values for the text:
generate totalcost = ".a" if Q1 == "not entered"
replace totalcost = 0 if Q1 == "got it for free"
replace totalcost = 5 if Q 1 == "monthly subscription"
but what I haven't managed to do is keep the same value for totalcost if Q1 already = a numeric value.
then I thought that away around this would be to generate total cost = Q1
then
replace totalcost = 0 if Q1 == "got it for free"
replace totalcost = 5 if Q 1 == "monthly subscription"
replace totalcost = ".a" if Q1 == "not entered"
but I'm getting 'Type Mismatch' I'm assuming because the original is a string - is there a way around this?
Any thoughts much appreciated.