I am using Ben Jann’s Duncan SSC package to calculate a dissimilarity index for each month and year.
My data includes industries, race, year and month. I would like to store the results (i.e. the dissimilarity index for each observation based on the year and month).
I have tried using the advice + code provided here (https://www.statalist.org/forums/for...a-new-variable)
Code:
egen year_month = group( MONTH YEAR ) sum year_month local max = r(max) ge dissindex = . forval x = 1/`max' { duncan INDUSTRY NATION if year_month == `x' replace dissindex = r(D) if year_month == `x' }
conformability error
r(503);
How can I fix this? Or is there an easier way to get the dissim index and store it as a new variable?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long CASE byte(INDUSTRY NATION MONTH) int YEAR 1601 30 1 2 2018 1602 46 1 2 2018 1701 86 1 1 2018 1702 86 2 1 2018 1801 85 1 1 2018 1802 47 1 9 2018 1902 13 1 2 2018 2001 87 1 2 2018 2002 41 1 2 2018 2003 47 1 2 2018 2004 45 1 2 2018 2101 84 1 3 2018 2102 33 1 6 2018 2103 55 1 3 2018 2402 25 1 9 2018 2403 47 1 9 2018 2504 41 1 10 2020 2601 86 1 1 2018 2602 35 1 1 2018 2802 24 1 2 2018 2901 28 1 1 2018 3202 84 1 3 2018 3302 55 3 6 2018 3402 64 1 4 2018 3501 68 1 3 2018 3601 85 1 1 2018 3602 58 1 1 2018 3701 29 3 3 2018 3801 84 1 1 2018 3802 85 1 1 2018 3901 90 1 3 2018 3902 71 1 3 2018 3904 86 6 4 2020 3905 30 6 4 2020 4001 86 10 2 2018 4301 86 1 1 2018 4302 85 1 4 2018 4402 85 3 5 2018 4501 96 1 1 2018 4502 47 1 1 2018 4602 85 1 1 2018 4603 33 1 1 2018 4604 52 1 1 2018 4702 69 1 3 2018 4703 69 1 3 2018 4801 85 3 3 2018 4802 49 1 3 2018 4901 85 1 2 2018 4902 85 1 5 2018 5001 68 1 3 2018 5102 71 1 2 2018 5301 62 1 1 2018 5401 47 1 4 2018 5402 62 1 9 2018 5601 85 1 3 2018 5602 52 1 3 2018 5701 84 1 1 2018 5702 24 1 4 2018 5801 85 1 1 2018 5904 68 1 5 2018 6001 85 1 2 2018 6002 71 1 2 2018 6101 86 1 1 2018 6102 85 1 1 2018 6501 59 1 2 2018 6502 59 1 2 2018 6701 42 1 3 2018 6702 25 1 3 2018 6703 47 1 3 2018 6801 55 3 3 2018 6802 87 3 3 2018 6803 93 1 11 2018 6804 85 10 11 2018 7003 41 1 4 2018 7103 86 1 2 2020 7201 46 1 2 2018 7203 93 1 8 2018 7301 49 1 1 2018 7303 1 1 10 2018 7502 22 1 8 2018 7602 52 1 10 2018 7701 59 1 1 2018 7702 85 1 1 2018 7704 56 1 1 2018 7802 86 1 4 2018 7803 92 10 5 2019 7902 46 1 2 2018 8001 87 1 2 2018 8002 38 1 2 2018 8003 86 1 2 2018 8102 47 3 7 2018 8201 47 3 3 2018 8202 52 3 3 2018 8301 85 1 1 2018 8402 52 1 2 2018 8501 61 1 2 2018 8502 90 1 2 2018 8602 25 1 3 2018 8603 56 1 10 2018 8703 86 1 4 2020 end label values INDUSTRY INDD07M label def INDD07M 1 "01 Crop, animal production, hunting", modify label def INDD07M 13 "13 Manufacture of textiles", modify label def INDD07M 22 "22 Manufacture rubber plastic products", modify label def INDD07M 24 "24 Manufacture of basic metals", modify label def INDD07M 25 "25 Manuf fab metal prods, ex machinery", modify label def INDD07M 28 "28 Manuf of machinery n.e.c.", modify label def INDD07M 29 "29 Manuf vehicles and trailers", modify label def INDD07M 30 "30 Manufacture of other transport", modify label def INDD07M 33 "33 Repair and installation of machinery", modify label def INDD07M 35 "35 Electricity, gas and air cond supply", modify label def INDD07M 38 "38 Waste collectn, treatment, disposal", modify label def INDD07M 41 "41 Construction of buildings", modify label def INDD07M 42 "42 Civil engineering", modify label def INDD07M 45 "45 Wholesale retail trade repair vehcls", modify label def INDD07M 46 "46 Wholesale trade, except vehicles", modify label def INDD07M 47 "47 Retail trade, except vehicles", modify label def INDD07M 49 "49 Land transport inc via pipelines", modify label def INDD07M 52 "52 Warehousing & support for transport", modify label def INDD07M 55 "55 Accommodation", modify label def INDD07M 56 "56 Food and beverage service activities", modify label def INDD07M 58 "58 Publishing activities", modify label def INDD07M 59 "59 Film, video, television sound record", modify label def INDD07M 61 "61 Telecommunications", modify label def INDD07M 62 "62 Computer programming and consultancy", modify label def INDD07M 64 "64 Financial ex insurance and pension", modify label def INDD07M 68 "68 Real estate activities", modify label def INDD07M 69 "69 Legal and accounting activities", modify label def INDD07M 71 "71 Architerctural and engineering", modify label def INDD07M 84 "84 Public admin, defence, social sec", modify label def INDD07M 85 "85 Education", modify label def INDD07M 86 "86 Human health activities", modify label def INDD07M 87 "87 Residential care activities", modify label def INDD07M 90 "90 Creative, arts and entertainment", modify label def INDD07M 92 "92 Gambling and betting activities", modify label def INDD07M 93 "93 Sports, amusement, recreation", modify label def INDD07M 96 "96 Other personal service activities", modify label values NATION ETHGBEUL label def ETHGBEUL 1 "White British", modify label def ETHGBEUL 2 "White Irish", modify label def ETHGBEUL 3 "Other White", modify label def ETHGBEUL 6 "Pakistani", modify label def ETHGBEUL 10 "Black/African/Caribbean/Black British", modify label values MONTH REFWKM label def REFWKM 1 "January", modify label def REFWKM 2 "February", modify label def REFWKM 3 "March", modify label def REFWKM 4 "April", modify label def REFWKM 5 "May", modify label def REFWKM 6 "June", modify label def REFWKM 7 "July", modify label def REFWKM 8 "August", modify label def REFWKM 9 "September", modify label def REFWKM 10 "October", modify label def REFWKM 11 "November", modify label values YEAR REFWKY
0 Response to calculating dissim index and storing results.
Post a Comment