Hi,
My apologies for bothering you with such a simple query. I am trying to do a simple division. I have 100+ variables. I have years ranging from 2016 to 2021. Several variables with prefix "rev" and "exp".
I want to generate ratios such as:
share_variable_year = rev_variable_year/exp_variable_year * 100
Manually it takes a lot of time. I was trying with loops. But could not do. Would appreciate it if anybody could kindly help with this.
I have provided the data example below.
Thank you in advance.
My apologies for bothering you with such a simple query. I am trying to do a simple division. I have 100+ variables. I have years ranging from 2016 to 2021. Several variables with prefix "rev" and "exp".
I want to generate ratios such as:
share_variable_year = rev_variable_year/exp_variable_year * 100
Code:
Example: gen share_soc_services2016 = rev_soc_services2016/exp_soc_services2016 * 100
I have provided the data example below.
Code:
* Example generated by -dataex-. For more info, type help dataex. clear input str2 stcode double(rev_soc_services2016 rev_soc_services2017 rev_mph2016 rev_mph2017 exp_soc_services2016 exp_soc_services2017 exp_mph2016 exp_mph2017) "AP" 1617.8866 -569.6508 83.3561 171.7518 50227.8676 59159.3498 4694.1987 4450.0773 "AS" 44.53400000000001 74.01769999999998 12.3265 22.6839 22673.142 21373.1693 2904.3253 3909.8413 "BR" 75.55640000000001 124.0436 39.938 54.5251 40736.6335 45769.4657 4189.1222 5064.1755 "CT" 145.5563 154.619 46.4967 52.557 21341.6112 24371.5905 2768.8327 3376.4992 "GJ" 3226.12 1183.74 981.9799999999999 173.81 44926.02 49039 5208.13 5575.9 "HR" 1455.414 3896.788500000001 31.1714 189.3393 25473.4883 28061.3383 2630.7664 2903.6326 "JH" 368.1921491 673.0495 20.5277172 14.224 18554.2114 19574.4642 1878.4059 2458.1713 "KA" 485.8977 725.8508 152.8966 364.2229 54549.2409 58652.3505 5510.7134 6354.081 "KL" 539.5639060999999 484.2157954 218.2200626 181.5287666 33764.7176421 35876.2711827 5219.097365 5599.2505825 "MH" 2338.763 3221.5086 448.9098 474.5921 90281.99080000001 93054.30140000001 9436.386600000002 10782.2731 "MP" 2338.6357 1608.4078 167.0393 128.9848 47942.4287 58346.1741 5002.7372 6005.6748 "OD" 208.9032 208.6337 50.8295 57.794 27599.9527 29556.82729999999 3735.717 3805.5595 "PB" 416.1993000000001 505.3808999999999 135.4685 253.3449 15672.0959 15469.7428 2670.9508 2533.9534 "RJ" 1324.2686 1326.7841 125.3859 130.6745 49371.6819 53064.07059999998 5453.674199999999 6696.968100000001 "TN" 2806.1828 2767.9652 422.796 516.7006000000001 55297.2662 59790.17369999999 6160.9064 7991.2386 "TS" 1993.0317 711.4556999999998 183.3157 261.5749 35285.562 37259.29060000001 3343.1856 3408.0746 "UP" 14653.2236 1571.1239 185.7238 260.4981 91861.1231 84251.683 7898.2315 9499.0179 "WB" 380.3331000000001 341.5845 134.7799 210.4753 57066.8386 59590.75519999999 6355.144399999999 7204.097299999999 end
Thank you in advance.
Comment