Hello everyone,

I'm working with basic monthly sample of CPS and I'd like to calculate for each occupation (occ2010) what's the share of working hours for African American people compared to the total race. This is how I've coded so far. Let me know if I did it right or wrong because I'm not entirely sure about the code.

Code:

egen occ_hours=sum(ahrswork1), by(month year serial occ2010 black)
egen totalv_occ_hours=sum(ahrswork1), by(month year serial occ2010 race)
gen share_black_working_hours =(occ_hours/totalv_occ_hours)

Following is the example of my dataset where ahrswork1 is the hours worked in last week , serial is the tag of each person, cpsidp is the id through which you can detect the same person appearing in different wave of cps interview on 4-8-4 monthly gap basis, occ2010 is the different set of occupation and the rest of it is pretty self explanatory:

. dataex month year serial cpsidp ahrswork1 occ2010 black race

----------------------- copy starting from the next line -----------------------
[CODE]
* Example generated by -dataex-. For more info, type help dataex
clear
input byte month int year long serial double cpsidp int(ahrswork1 occ2010) float black int race
1 1996 347 19951100051902 44 7700 0 100
1 1996 170 19951100016002 40 5700 0 100
1 1996 584 19960100058401 999 9999 1 200
1 1996 66 19951100002101 999 9999 1 200
1 1996 49 19951200004503 40 9620 1 200
1 1996 479 19951200037202 35 4510 0 100
1 1996 77 19951000007902 999 9999 0 100
1 1996 475 19951100043603 11 5160 0 100
1 1996 775 19951100076401 999 8965 0 100
1 1996 763 19951000076601 999 9999 0 100
1 1996 119 19951100008803 44 5820 0 100
1 1996 503 19951200039302 35 6050 0 100
1 1996 104 19951100006403 999 9999 1 200
1 1996 774 19951100062202 25 4720 0 100
1 1996 743 19951000074502 40 4840 0 100
1 1996 674 19960100067401 42 430 0 100
1 1996 406 19951000039902 40 5700 0 100
1 1996 48 19951100008701 999 9999 0 100
1 1996 539 19960100053902 40 9130 0 100
1 1996 229 19951000022402 32 5310 0 100
1 1996 604 19951000060101 999 9999 0 100
1 1996 71 19951200004202 40 5120 0 100
1 1996 204 19951100020901 999 9999 0 100
1 1996 67 19951100007401 35 430 1 200
1 1996 137 19951100017502 15 2340 0 100
1 1996 342 19951000033701 40 4000 1 200
1 1996 326 19951100041801 43 8310 0 100
1 1996 553 19951000055001 36 8320 1 200
1 1996 393 19951100050401 40 8740 0 100
1 1996 238 19951000023102 999 9999 0 100
1 1996 68 19951200001201 50 4760 0 100
1 1996 735 19951200077403 999 9999 0 100