Hi,

If this is my data-
day totalpay hours
Sunday 500 5
Monday 750 50
Tuesday 325 25
Wednesday 900 100
And I'm trying to create a new variable "dayavg" where "dayavg = totalpay/hours" on Monday, Tuesday and Wednesday, else "dayavg = totalpay/50."

This is the code I'm using -

Code:
encode totalpay, generate(totalpay2)
encode hours, generate(hours2)

gen dayavg = 0
replace dayavg = totalpay2/hours2 if day == "Monday" | day == "Tuesday" | day == "Wednesday"
else replace dayavg = totalpay2/50
And this is the output I'm getting-
day totalpay hours totalpay2 hours2 dayavg
Sunday 500 5 500 5 0.04
Monday 750 50 750 50 0.06
Tuesday 325 25 325 25 0.02
Wednesday 900 100 900 100 0.08
Where am I going wrong?