I want to create a variable based on a couple conditions and haven't found an example to apply to my situation. I want a variable in dollars for daily pay. My dataset includes 2 currencies. If individuals are in Honduras (coded 2 below) and have a daily rate, I want to calculate that by the exchange rate to know what the rate would be in dollars. For individuals in El Salvador, the currency is already in dollars so I have been trying and failing using these syntax:
gen pago_dia_dol = (pago_dia * 0.040317) if pais == 2 | = pago_dia if pais == 1
here it is in english:
gen daily_pay_dollars = daily_pay * 0.040317) if country == 2 | = daily_pay if pais == 1
Please advise! thank you!
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str15 id_beneficiario byte pais float(moneda pago_dia) "Hhr-005e9e8-13b" 1 . . "Hhr-00d90fa-e7a" 2 . . "Hhr-0115e72-290" 2 . . "Hhr-013440f-718" 1 . . "Hhr-0147fdd-fc0" 2 . . "Hhr-0149bcf-f70" 2 . . "Hhr-015c441-dd8" 1 . . "Hhr-016cbf9-e7d" 2 . 200 "Hhr-0174723-be8" 2 . . "Hhr-0185bb7-25a" 1 . . "Hhr-018adb7-d39" 2 . . "Hhr-019567a-34c" 2 . 66.666664 "Hhr-01c8d31-536" 2 . . "Hhr-01d086d-fe6" 1 . . "Hhr-01eea82-c2f" 1 . . "Hhr-01f2381-e29" 2 . . "Hhr-01f3f37-4ac" 2 . 58.33333 "Hhr-0222c8a-3b9" 1 . . "Hhr-022b147-545" 1 . 12.5 "Hhr-0245620-343" 1 . . end label values pais lblpais label def lblpais 1 "El Salvador", modify label def lblpais 2 "Honduras", modify label values moneda lblmoneda
0 Response to Gen variable w Conditions & Calculation
Post a Comment