Hello everyone,
I have a problem with data that I need to transform. I need to transform a string variable into a numeric variable. I then need to use this variable to do further calculations.
However, when for example I try to do the following calculation, I don't get all the values equal to 1 for the observations greater than 1000$. Why is this, could someone please help me.
I have been struggling with something this "simple" for a while now:
Here a sample:
I have a problem with data that I need to transform. I need to transform a string variable into a numeric variable. I then need to use this variable to do further calculations.
Code:
encode(ca_netpay),gen(ca_netpay_num) // convert string to long format label var ca_netpay_num "numerical ca_netpay_num" sort ca_netpay_num tab ca_netpay_num tab ca_netpay_num, missing nolabel // refind the numerical values behind labels * *set the variable to "missing" for all individuals where a numeric value is not available replace ca_netpay_num = . if ca_netpay_num >= 1614
However, when for example I try to do the following calculation, I don't get all the values equal to 1 for the observations greater than 1000$. Why is this, could someone please help me.
I have been struggling with something this "simple" for a while now:
Code:
bys ca_sex: summarize less_happy if ca_netpay_num >1000
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte ca_sex long ca_netpay_num float yes 1 663 0 1 726 0 1 1 0 1 1081 1 1 3 0 1 112 0 1 1245 1 1 1081 1 1 . 1 1 1081 1 1 927 0 1 623 0 1 668 0 1 1111 1 1 . 1 1 1081 1 1 . 1 1 278 0 1 1487 1 1 1081 1 1 806 0 1 1081 1 1 1360 1 1 1081 1 1 . 1 1 505 0 1 1515 1 1 2 0 1 6 0 1 853 0 1 1487 1 1 3 0 1 1170 1 1 3 0 1 . 1 1 . 1 1 435 0 1 . 1 1 726 0 1 107 0 end label values ca_sex ca_sex label def ca_sex 1 "Male", modify label values ca_netpay_num ca_netpay_num label def ca_netpay_num 2 ".", modify label def ca_netpay_num 3 "0", modify label def ca_netpay_num 6 "100", modify label def ca_netpay_num 107 "1150", modify label def ca_netpay_num 112 "1156", modify label def ca_netpay_num 278 "1400", modify label def ca_netpay_num 435 "1670", modify label def ca_netpay_num 505 "1800", modify label def ca_netpay_num 623 "200", modify label def ca_netpay_num 663 "2075", modify label def ca_netpay_num 668 "2090", modify label def ca_netpay_num 726 "2200", modify label def ca_netpay_num 806 "2400", modify label def ca_netpay_num 853 "250", modify label def ca_netpay_num 927 "2750", modify label def ca_netpay_num 1081 "3300", modify label def ca_netpay_num 1111 "35000", modify label def ca_netpay_num 1170 "3890", modify label def ca_netpay_num 1245 "4500", modify label def ca_netpay_num 1360 "600", modify label def ca_netpay_num 1487 "800", modify label def ca_netpay_num 1515 "850", modify
Comment