I have been struggling with computing average by group, and I know that it is done with very simple code.
However, the problem is that when I calculate in STATA, the mean value is actually very different from what I get using a calculator.
Therefore, I would like to know how these mean values are created and how to get an "exact" average value by each indicator by sector.
Below is my dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str31 STRI_sector int year long(Indicator_STRI Restrictions_on_foreignentry Restrictions_to_movement_of_peop Other_discriminatory_measures Barriers_to_competition Regulatory_transparency STRI_s) float m_ind_STRI "Accounting" 2014 6 17 32 4 4 7 1 8.285714 "Air transport" 2014 41 35 2 16 25 3 2 40.42857 "Architecture" 2014 4 4 32 11 6 12 3 6.857143 "Broadcasting" 2014 33 33 5 21 14 8 4 32.42857 "Commercial banking" 2014 19 24 6 17 18 10 5 18.285715 "Computer" 2014 34 27 31 15 11 14 6 35.142857 "Construction" 2014 35 20 34 22 12 11 7 36.142857 "Courier" 2014 39 30 12 14 24 18 8 34.285713 "Distribution" 2014 18 19 8 8 20 14 9 15.857142 "Engineering" 2014 11 11 33 7 5 12 10 19.57143 "Insurance" 2014 17 29 14 12 9 9 11 18.714285 "Legal" 2014 27 25 36 5 2 6 12 29.285715 "Logistics cargo-handling" 2014 22 7 9 6 23 17 13 22.57143 "Logistics customs brokerage" 2014 28 21 17 15 8 20 14 28 "Logistics freight forwarding" 2014 15 12 13 9 8 21 15 15.571428 "Logistics storage and warehouse" 2014 23 10 11 7 21 19 16 23.57143 "Maritime transport" 2014 7 25 25 3 10 5 17 9.857142 "Motion pictures" 2014 29 18 28 20 7 13 18 26.714285 "Rail freight transport" 2014 1 1 1 1 1 1 19 1 "Road freight transport" 2014 22 31 22 10 13 2 20 20.857143 "Sound recording" 2014 30 3 26 23 16 16 21 27.714285 "Telecom" 2014 2 14 3 2 19 4 22 3.857143 "Accounting" 2015 6 17 32 4 4 7 1 8.285714 "Air transport" 2015 41 35 2 16 25 3 2 40.42857 "Architecture" 2015 4 4 32 11 6 12 3 6.857143 "Broadcasting" 2015 33 33 5 21 14 8 4 32.42857 "Commercial banking" 2015 19 24 6 17 18 10 5 18.285715 "Computer" 2015 34 27 31 15 11 14 6 35.142857 "Construction" 2015 35 20 34 22 12 11 7 36.142857 "Courier" 2015 39 30 12 14 24 18 8 34.285713 "Distribution" 2015 18 19 8 8 20 14 9 15.857142 "Engineering" 2015 11 11 33 7 5 12 10 19.57143 "Insurance" 2015 17 29 14 12 9 9 11 18.714285 "Legal" 2015 27 25 36 5 2 6 12 29.285715 "Logistics cargo-handling" 2015 22 7 9 6 23 17 13 22.57143 "Logistics customs brokerage" 2015 28 21 17 15 8 20 14 28 "Logistics freight forwarding" 2015 15 12 13 9 8 21 15 15.571428 "Logistics storage and warehouse" 2015 23 10 11 7 21 19 16 23.57143 "Maritime transport" 2015 7 25 25 3 10 5 17 9.857142 "Motion pictures" 2015 29 18 28 20 7 13 18 26.714285 "Rail freight transport" 2015 1 1 1 1 1 1 19 1 "Road freight transport" 2015 22 31 22 10 13 2 20 20.857143 "Sound recording" 2015 30 3 26 23 16 16 21 27.714285 "Telecom" 2015 2 14 3 2 19 4 22 3.857143 "Accounting" 2016 6 17 32 4 4 7 1 8.285714 "Air transport" 2016 41 35 2 16 25 3 2 40.42857 "Architecture" 2016 4 4 32 11 6 12 3 6.857143 "Broadcasting" 2016 33 33 5 21 14 8 4 32.42857 "Commercial banking" 2016 19 24 6 17 18 10 5 18.285715 "Computer" 2016 34 27 31 15 11 14 6 35.142857 "Construction" 2016 35 20 34 22 12 11 7 36.142857 "Courier" 2016 39 30 12 14 24 18 8 34.285713 "Distribution" 2016 18 19 8 8 20 14 9 15.857142 "Engineering" 2016 11 11 33 7 5 12 10 19.57143 "Insurance" 2016 17 29 14 12 9 9 11 18.714285 "Legal" 2016 27 25 36 5 2 6 12 29.285715 "Logistics cargo-handling" 2016 22 7 9 6 23 17 13 22.57143 "Logistics customs brokerage" 2016 28 21 17 15 8 20 14 28 "Logistics freight forwarding" 2016 15 12 13 9 8 21 15 15.571428 "Logistics storage and warehouse" 2016 23 10 11 7 21 19 16 23.57143 "Maritime transport" 2016 7 25 25 3 10 5 17 9.857142 "Motion pictures" 2016 29 18 28 20 7 13 18 26.714285 "Rail freight transport" 2016 1 1 1 1 1 1 19 1 "Road freight transport" 2016 22 31 22 10 13 2 20 20.857143 "Sound recording" 2016 30 3 26 23 16 16 21 27.714285 "Telecom" 2016 3 14 3 13 14 4 22 3.857143 "Accounting" 2017 10 13 35 4 4 7 1 8.285714 "Air transport" 2017 40 34 4 16 25 3 2 40.42857 "Architecture" 2017 9 4 38 11 6 12 3 6.857143 "Broadcasting" 2017 32 32 9 19 14 8 4 32.42857 "Commercial banking" 2017 19 21 10 17 18 10 5 18.285715 "Computer" 2017 36 23 37 15 11 14 6 35.142857 "Construction" 2017 37 20 39 22 12 11 7 36.142857 "Courier" 2017 38 27 18 14 24 18 8 34.285713 "Distribution" 2017 18 15 15 8 20 14 9 15.857142 "Engineering" 2017 26 11 40 7 5 12 10 19.57143 "Insurance" 2017 21 28 23 12 9 9 11 18.714285 "Legal" 2017 31 22 41 5 2 6 12 29.285715 "Logistics cargo-handling" 2017 23 5 17 6 23 17 13 22.57143 "Logistics customs brokerage" 2017 29 16 24 15 8 20 14 28 "Logistics freight forwarding" 2017 16 8 21 9 8 21 15 15.571428 "Logistics storage and warehouse" 2017 24 6 19 7 21 19 16 23.57143 "Maritime transport" 2017 12 19 31 3 10 5 17 9.857142 "Motion pictures" 2017 25 13 30 18 3 13 18 26.714285 "Rail freight transport" 2017 1 1 1 1 1 1 19 1 "Road freight transport" 2017 20 26 27 10 13 2 20 20.857143 "Sound recording" 2017 26 2 29 23 13 16 21 27.714285 "Telecom" 2017 5 14 7 13 22 4 22 3.857143 "Accounting" 2018 10 13 35 4 4 7 1 8.285714 "Air transport" 2018 40 34 4 16 25 3 2 40.42857 "Architecture" 2018 9 4 38 11 6 12 3 6.857143 "Broadcasting" 2018 32 32 9 19 14 8 4 32.42857 "Commercial banking" 2018 19 21 10 17 18 10 5 18.285715 "Computer" 2018 36 23 37 15 11 14 6 35.142857 "Construction" 2018 37 20 39 22 12 11 7 36.142857 "Courier" 2018 38 27 18 14 24 18 8 34.285713 "Distribution" 2018 18 15 15 8 20 14 9 15.857142 "Engineering" 2018 26 11 40 7 5 12 10 19.57143 "Insurance" 2018 21 28 23 12 9 9 11 18.714285 "Legal" 2018 31 22 41 5 2 6 12 29.285715 end label values Indicator_STRI Indicator_STRI label def Indicator_STRI 1 "..", modify label def Indicator_STRI 2 ".283", modify label def Indicator_STRI 3 ".29", modify label def Indicator_STRI 4 ".312", modify label def Indicator_STRI 5 ".319", modify label def Indicator_STRI 6 ".335", modify label def Indicator_STRI 7 ".338", modify label def Indicator_STRI 9 ".342", modify label def Indicator_STRI 10 ".343", modify label def Indicator_STRI 11 ".344", modify label def Indicator_STRI 12 ".345", modify label def Indicator_STRI 15 ".349", modify label def Indicator_STRI 16 ".35", modify label def Indicator_STRI 17 ".354", modify label def Indicator_STRI 18 ".357", modify label def Indicator_STRI 19 ".358", modify label def Indicator_STRI 20 ".364", modify label def Indicator_STRI 21 ".366", modify label def Indicator_STRI 22 ".367", modify label def Indicator_STRI 23 ".369", modify label def Indicator_STRI 24 ".371", modify label def Indicator_STRI 25 ".372", modify label def Indicator_STRI 26 ".375", modify label def Indicator_STRI 27 ".382", modify label def Indicator_STRI 28 ".39", modify label def Indicator_STRI 29 ".392", modify label def Indicator_STRI 30 ".397", modify label def Indicator_STRI 31 ".399", modify label def Indicator_STRI 32 ".406", modify label def Indicator_STRI 33 ".421", modify label def Indicator_STRI 34 ".428", modify label def Indicator_STRI 35 ".442", modify label def Indicator_STRI 36 ".443", modify label def Indicator_STRI 37 ".464", modify label def Indicator_STRI 38 ".483", modify label def Indicator_STRI 39 ".484", modify label def Indicator_STRI 40 ".508", modify label def Indicator_STRI 41 ".514", modify label values Restrictions_on_foreignentry Restrictions_on_foreignentry label def Restrictions_on_foreignentry 1 "..", modify label def Restrictions_on_foreignentry 2 ".079", modify label def Restrictions_on_foreignentry 3 ".095", modify label def Restrictions_on_foreignentry 4 ".1", modify label def Restrictions_on_foreignentry 5 ".112", modify label def Restrictions_on_foreignentry 6 ".119", modify label def Restrictions_on_foreignentry 7 ".124", modify label def Restrictions_on_foreignentry 8 ".127", modify label def Restrictions_on_foreignentry 10 ".132", modify label def Restrictions_on_foreignentry 11 ".136", modify label def Restrictions_on_foreignentry 12 ".141", modify label def Restrictions_on_foreignentry 13 ".144", modify label def Restrictions_on_foreignentry 14 ".146", modify label def Restrictions_on_foreignentry 15 ".152", modify label def Restrictions_on_foreignentry 16 ".154", modify label def Restrictions_on_foreignentry 17 ".155", modify label def Restrictions_on_foreignentry 18 ".159", modify label def Restrictions_on_foreignentry 19 ".164", modify label def Restrictions_on_foreignentry 20 ".167", modify label def Restrictions_on_foreignentry 21 ".168", modify label def Restrictions_on_foreignentry 22 ".171", modify label def Restrictions_on_foreignentry 23 ".176", modify label def Restrictions_on_foreignentry 24 ".18", modify label def Restrictions_on_foreignentry 25 ".181", modify label def Restrictions_on_foreignentry 26 ".191", modify label def Restrictions_on_foreignentry 27 ".192", modify label def Restrictions_on_foreignentry 28 ".196", modify label def Restrictions_on_foreignentry 29 ".202", modify label def Restrictions_on_foreignentry 30 ".204", modify label def Restrictions_on_foreignentry 31 ".212", modify label def Restrictions_on_foreignentry 32 ".217", modify label def Restrictions_on_foreignentry 33 ".235", modify label def Restrictions_on_foreignentry 34 ".268", modify label def Restrictions_on_foreignentry 35 ".282", modify label values Restrictions_to_movement_of_peop Restrictions_to_movement_of_peop label def Restrictions_to_movement_of_peop 1 "..", modify label def Restrictions_to_movement_of_peop 2 ".028", modify label def Restrictions_to_movement_of_peop 3 ".032", modify label def Restrictions_to_movement_of_peop 4 ".036", modify label def Restrictions_to_movement_of_peop 5 ".038", modify label def Restrictions_to_movement_of_peop 6 ".039", modify label def Restrictions_to_movement_of_peop 7 ".041", modify label def Restrictions_to_movement_of_peop 8 ".046", modify label def Restrictions_to_movement_of_peop 9 ".049", modify label def Restrictions_to_movement_of_peop 10 ".05", modify label def Restrictions_to_movement_of_peop 11 ".052", modify label def Restrictions_to_movement_of_peop 12 ".055", modify label def Restrictions_to_movement_of_peop 13 ".056", modify label def Restrictions_to_movement_of_peop 14 ".057", modify label def Restrictions_to_movement_of_peop 15 ".058", modify label def Restrictions_to_movement_of_peop 17 ".063", modify label def Restrictions_to_movement_of_peop 18 ".065", modify label def Restrictions_to_movement_of_peop 19 ".067", modify label def Restrictions_to_movement_of_peop 21 ".072", modify label def Restrictions_to_movement_of_peop 22 ".073", modify label def Restrictions_to_movement_of_peop 23 ".076", modify label def Restrictions_to_movement_of_peop 24 ".079", modify label def Restrictions_to_movement_of_peop 25 ".082", modify label def Restrictions_to_movement_of_peop 26 ".089", modify label def Restrictions_to_movement_of_peop 27 ".091", modify label def Restrictions_to_movement_of_peop 28 ".093", modify label def Restrictions_to_movement_of_peop 29 ".101", modify label def Restrictions_to_movement_of_peop 30 ".104", modify label def Restrictions_to_movement_of_peop 31 ".106", modify label def Restrictions_to_movement_of_peop 32 ".108", modify label def Restrictions_to_movement_of_peop 33 ".109", modify label def Restrictions_to_movement_of_peop 34 ".118", modify label def Restrictions_to_movement_of_peop 35 ".128", modify label def Restrictions_to_movement_of_peop 36 ".134", modify label def Restrictions_to_movement_of_peop 37 ".137", modify label def Restrictions_to_movement_of_peop 38 ".138", modify label def Restrictions_to_movement_of_peop 39 ".139", modify label def Restrictions_to_movement_of_peop 40 ".14", modify label def Restrictions_to_movement_of_peop 41 ".161", modify label values Other_discriminatory_measures Other_discriminatory_measures label def Other_discriminatory_measures 1 "..", modify label def Other_discriminatory_measures 2 ".017", modify label def Other_discriminatory_measures 3 ".018", modify label def Other_discriminatory_measures 4 ".021", modify label def Other_discriminatory_measures 5 ".022", modify label def Other_discriminatory_measures 6 ".025", modify label def Other_discriminatory_measures 7 ".027", modify label def Other_discriminatory_measures 8 ".028", modify label def Other_discriminatory_measures 9 ".029", modify label def Other_discriminatory_measures 10 ".03", modify label def Other_discriminatory_measures 11 ".031", modify label def Other_discriminatory_measures 12 ".032", modify label def Other_discriminatory_measures 13 ".034", modify label def Other_discriminatory_measures 14 ".035", modify label def Other_discriminatory_measures 15 ".038", modify label def Other_discriminatory_measures 16 ".041", modify label def Other_discriminatory_measures 17 ".043", modify label def Other_discriminatory_measures 18 ".051", modify label def Other_discriminatory_measures 19 ".055", modify label def Other_discriminatory_measures 20 ".061", modify label def Other_discriminatory_measures 21 ".063", modify label def Other_discriminatory_measures 22 ".07", modify label def Other_discriminatory_measures 23 ".091", modify label values Barriers_to_competition Barriers_to_competition label def Barriers_to_competition 1 "..", modify label def Barriers_to_competition 2 ".013", modify label def Barriers_to_competition 3 ".014", modify label def Barriers_to_competition 4 ".015", modify label def Barriers_to_competition 5 ".018", modify label def Barriers_to_competition 6 ".02", modify label def Barriers_to_competition 7 ".021", modify label def Barriers_to_competition 8 ".023", modify label def Barriers_to_competition 9 ".024", modify label def Barriers_to_competition 10 ".027", modify label def Barriers_to_competition 11 ".031", modify label def Barriers_to_competition 12 ".035", modify label def Barriers_to_competition 13 ".036", modify label def Barriers_to_competition 14 ".048", modify label def Barriers_to_competition 16 ".053", modify label def Barriers_to_competition 18 ".057", modify label def Barriers_to_competition 19 ".058", modify label def Barriers_to_competition 20 ".059", modify label def Barriers_to_competition 21 ".064", modify label def Barriers_to_competition 22 ".068", modify label def Barriers_to_competition 23 ".08", modify label def Barriers_to_competition 24 ".101", modify label def Barriers_to_competition 25 ".138", modify label values Regulatory_transparency Regulatory_transparency label def Regulatory_transparency 1 "..", modify label def Regulatory_transparency 2 ".015", modify label def Regulatory_transparency 3 ".026", modify label def Regulatory_transparency 4 ".03", modify label def Regulatory_transparency 5 ".031", modify label def Regulatory_transparency 6 ".032", modify label def Regulatory_transparency 7 ".035", modify label def Regulatory_transparency 8 ".036", modify label def Regulatory_transparency 9 ".037", modify label def Regulatory_transparency 10 ".04", modify label def Regulatory_transparency 11 ".052", modify label def Regulatory_transparency 12 ".053", modify label def Regulatory_transparency 13 ".058", modify label def Regulatory_transparency 14 ".061", modify label def Regulatory_transparency 16 ".069", modify label def Regulatory_transparency 17 ".088", modify label def Regulatory_transparency 18 ".089", modify label def Regulatory_transparency 19 ".094", modify label def Regulatory_transparency 20 ".099", modify label def Regulatory_transparency 21 ".1", modify label values STRI_s STRI_s label def STRI_s 1 "Accounting", modify label def STRI_s 2 "Air transport", modify label def STRI_s 3 "Architecture", modify label def STRI_s 4 "Broadcasting", modify label def STRI_s 5 "Commercial banking", modify label def STRI_s 6 "Computer", modify label def STRI_s 7 "Construction", modify label def STRI_s 8 "Courier", modify label def STRI_s 9 "Distribution", modify label def STRI_s 10 "Engineering", modify label def STRI_s 11 "Insurance", modify label def STRI_s 12 "Legal", modify label def STRI_s 13 "Logistics cargo-handling", modify label def STRI_s 14 "Logistics customs brokerage", modify label def STRI_s 15 "Logistics freight forwarding", modify label def STRI_s 16 "Logistics storage and warehouse", modify label def STRI_s 17 "Maritime transport", modify label def STRI_s 18 "Motion pictures", modify label def STRI_s 19 "Rail freight transport", modify label def STRI_s 20 "Road freight transport", modify label def STRI_s 21 "Sound recording", modify label def STRI_s 22 "Telecom", modify
for information, m_ind_STRI is the value when I type the command below:
egen m_ind_STRI = mean(Indicator_STRI), by(STRI_s)
Best regards,
Anne Claire
0 Response to (Error) Calculating average by each group
Post a Comment