Hi,
In my data set, for each 'Unit', I have the data on the total number of food drives (between June 2020 - August 2020) and the total number of people who attended. What I want to generate (and is shown in the variable 'drives_week'), is the number of drives that took place by each week (ie, week 19 there was only 1 drive that took place but in week 25 2 drives took place. Is there a way I could generate this variable?
One way I'm doing this is:
Is there another way I can do this?
In my data set, for each 'Unit', I have the data on the total number of food drives (between June 2020 - August 2020) and the total number of people who attended. What I want to generate (and is shown in the variable 'drives_week'), is the number of drives that took place by each week (ie, week 19 there was only 1 drive that took place but in week 25 2 drives took place. Is there a way I could generate this variable?
One way I'm doing this is:
Code:
duplicates tag UnitCode week, g(drives_week) replace drives_week = drives_week + 1 keep Unit week drives_week duplicates drop
Is there another way I can do this?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str11 UnitCode int(NoofDrives noofpeople) str12 dy_str float(date week) byte drives_week "38a" 9 173 "07_May_2020 " 22042 19 1 "38a" 9 94 "14_Jun_2020 " 22080 24 1 "38a" 9 92 "23_Jun_2020 " 22089 25 2 "38a" 9 84 "19_Jun_2020 " 22085 25 2 "38a" 9 234 "24_Jun_2020 " 22090 26 2 "38a" 9 166 "25_Jun_2020 " 22091 26 2 "38a" 9 17 "05_Jul_2020 " 22101 27 1 "38a" 9 443 "30_Jul_2020 " 22126 31 1 "38a" 9 41 "31_Aug_2020 " 22158 35 1 "60a" 6 27 "20_Apr_2020 " 22025 16 2 "60a" 6 59 "21_Apr_2020 " 22026 16 2 "60a" 6 156 "09_Jun_2020 " 22075 23 3 "60a" 6 123 "08_Jun_2020 " 22074 23 3 "60a" 6 36 "07_Jun_2020 " 22073 23 3 "60a" 6 73 "21_Jun_2020 " 22087 25 1 "A39" 7 15 "19_Jun_2020 " 22085 25 3 "A39" 7 67 "18_Jun_2020 " 22084 25 3 "A39" 7 36 "17_Jun_2020 " 22083 25 3 "A39" 7 87 "26_Jun_2020 " 22092 26 2 "A39" 7 209 "24_Jun_2020 " 22090 26 2 "A39" 7 97 "18_Aug_2020 " 22145 33 1 "A39" 7 62 "19_Aug_2020 " 22146 34 1 "B01" 12 72 "20_Apr_2020 " 22025 16 1 "B01" 12 138 "08_Jun_2020 " 22074 23 1 "B01" 12 129 "15_Jun_2020 " 22081 24 2 "B01" 12 32 "14_Jun_2020 " 22080 24 2 "B01" 12 225 "21_Jun_2020 " 22087 25 4 "B01" 12 265 "20_Jun_2020 " 22086 25 4 "B01" 12 69 "17_Jun_2020 " 22083 25 4 "B01" 12 141 "19_Jun_2020 " 22085 25 4 "B01" 12 522 "30_Jun_2020 " 22096 26 2 "B01" 12 577 "24_Jun_2020 " 22090 26 2 "B01" 12 232 "13_Jul_2020 " 22109 28 1 "B01" 12 157 "27_Aug_2020 " 22154 35 1 "B02" 7 24 "12_Apr_2020 " 22017 15 1 "B02" 7 82 "21_Jun_2020 " 22087 25 3 "B02" 7 23 "19_Jun_2020 " 22085 25 3 "B02" 7 209 "18_Jun_2020 " 22084 25 3 "B02" 7 51 "03_Jul_2020 " 22099 27 1 "B02" 7 82 "23_Aug_2020 " 22150 34 1 "B02" 7 16 "27_Aug_2020 " 22154 35 1 "B03" 4 303 "18_Jun_2020 " 22084 25 3 "B03" 4 14 "22_Jun_2020 " 22088 25 3 "B03" 4 1195 "21_Jun_2020 " 22087 25 3 "B03" 4 46 "25_Aug_2020 " 22152 34 1 "B04" 9 35 "12_Apr_2020 " 22017 15 1 "B04" 9 11 "17_Apr_2020 " 22022 16 2 "B04" 9 20 "16_Apr_2020 " 22021 16 2 "B04" 9 178 "18_Jun_2020 " 22084 25 3 "B04" 9 282 "21_Jun_2020 " 22087 25 3 "B04" 9 207 "22_Jun_2020 " 22088 25 3 "B04" 9 51 "25_Aug_2020 " 22152 34 1 "B04" 9 82 "27_Aug_2020 " 22154 35 2 "B04" 9 55 "26_Aug_2020 " 22153 35 2 "B05" 10 13 "25_May_2020 " 22060 21 2 "B05" 10 14 "21_May_2020 " 22056 21 2 "B05" 10 12 "29_May_2020 " 22064 22 3 "B05" 10 25 "31_May_2020 " 22066 22 3 "B05" 10 19 "27_May_2020 " 22062 22 3 "B05" 10 23 "19_Jun_2020 " 22085 25 4 "B05" 10 14 "20_Jun_2020 " 22086 25 4 "B05" 10 375 "18_Jun_2020 " 22084 25 4 "B05" 10 214 "21_Jun_2020 " 22087 25 4 "B05" 10 66 "24_Aug_2020 " 22151 34 1 "B06" 7 94 "10_Apr_2020 " 22015 15 1 "B06" 7 57 "16_Jun_2020 " 22082 24 1 "B06" 7 790 "21_Jun_2020 " 22087 25 2 "B06" 7 252 "22_Jun_2020 " 22088 25 2 "B06" 7 61 "03_Jul_2020 " 22099 27 1 "B06" 7 119 "17_Aug_2020 " 22144 33 1 "B06" 7 51 "27_Aug_2020 " 22154 35 1 "B07" 9 204 "12_Apr_2020 " 22017 15 1 "B07" 9 86 "17_Apr_2020 " 22022 16 1 "B07" 9 91 "01_Jun_2020 " 22067 22 1 "B07" 9 86 "11_Jun_2020 " 22077 24 3 "B07" 9 273 "12_Jun_2020 " 22078 24 3 "B07" 9 320 "14_Jun_2020 " 22080 24 3 "B07" 9 673 "21_Jun_2020 " 22087 25 2 "B07" 9 351 "22_Jun_2020 " 22088 25 2 "B07" 9 11 "02_Aug_2020 " 22129 31 1 "B08" 17 57 "12_May_2020 " 22047 19 1 "B08" 17 30 "18_May_2020 " 22053 20 1 "B08" 17 14 "25_May_2020 " 22060 21 1 "B08" 17 23 "27_May_2020 " 22062 22 1 "B08" 17 12 "14_Jun_2020 " 22080 24 3 "B08" 17 15 "15_Jun_2020 " 22081 24 3 "B08" 17 13 "16_Jun_2020 " 22082 24 3 "B08" 17 425 "22_Jun_2020 " 22088 25 4 "B08" 17 12 "18_Jun_2020 " 22084 25 4 "B08" 17 96 "21_Jun_2020 " 22087 25 4 "B08" 17 62 "23_Jun_2020 " 22089 25 4 "B08" 17 687 "24_Jun_2020 " 22090 26 2 "B08" 17 18 "28_Jun_2020 " 22094 26 2 "B08" 17 87 "03_Jul_2020 " 22099 27 1 "B08" 17 28 "16_Jul_2020 " 22112 29 3 "B08" 17 115 "20_Jul_2020 " 22116 29 3 "B08" 17 490 "17_Jul_2020 " 22113 29 3 "B09" 20 102 "08_Apr_2020 " 22013 15 2 "B09" 20 98 "09_Apr_2020 " 22014 15 2 "B09" 20 12 "22_May_2020 " 22057 21 2 end format %td date
Comment