If this is my data-
day | totalpay | hours |
Sunday | 500 | 5 |
Monday | 750 | 50 |
Tuesday | 325 | 25 |
Wednesday | 900 | 100 |
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
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 |
0 Response to Calculations with if statements
Post a Comment