Hi All,
In my data the three variables of w_id, w_date and value are from one dataset and I want to use them to create new_value for the other dataset which includes n_id and n_date. The problem is that the weeks in these two datasets don’t match. So, I want to create a new value variable using proportions of weeks in the first dataset (w_id, w_date, and value).
For example first two weeks in w_id and w_date are:
From 18993 to 19000 with value of 1.23 and 19000-19007 with value of 1.46
The first week in n_id and n_date is from 18996 to 19003 which means it has 4 days from the first week and 3 days from the second week in w_date data. So, I want to create new_value=(4/7)*1.23 +(3/7)*1.46. But these proportions are not always 4/7 and 3/7 and change throughout the data.
Here is a sample of my data:
I really appreciate your help.
In my data the three variables of w_id, w_date and value are from one dataset and I want to use them to create new_value for the other dataset which includes n_id and n_date. The problem is that the weeks in these two datasets don’t match. So, I want to create a new value variable using proportions of weeks in the first dataset (w_id, w_date, and value).
For example first two weeks in w_id and w_date are:
From 18993 to 19000 with value of 1.23 and 19000-19007 with value of 1.46
The first week in n_id and n_date is from 18996 to 19003 which means it has 4 days from the first week and 3 days from the second week in w_date data. So, I want to create new_value=(4/7)*1.23 +(3/7)*1.46. But these proportions are not always 4/7 and 3/7 and change throughout the data.
Here is a sample of my data:
Code:
clear input int w_id int w_date int n_id int n_date float value 1 18993 1 18996 1.23 2 19000 2 19003 1.46 3 19007 3 19010 1.69 4 19014 4 19017 1.92 5 19021 5 19024 2.15 6 19028 6 19031 2.38 7 19035 7 19038 2.61 8 19042 8 19045 2.84 9 19049 9 19052 3.07 10 19056 10 19059 3.8 11 19063 11 19066 3.03 12 19070 12 19073 3.26 13 19077 13 19080 3.49 14 19084 14 19087 3.72 15 19091 15 19094 3.95 16 19098 16 19101 4.18 17 19105 17 19108 4.41 18 19112 18 19115 4.64 19 19119 19 19122 4.87 20 19126 20 19129 5.1 21 19133 21 19136 4.83 22 19140 22 19143 5.06 23 19147 23 19150 5.29 24 19154 24 19157 5.52 25 19161 25 19164 5.75 26 19168 26 19171 5.98 27 19175 27 19185 6.21 28 19182 28 19192 6.44 29 19189 29 19199 6.67 30 19196 30 19206 6.9 31 19203 31 19213 7.13 32 19210 32 19220 7.36 33 19217 33 19227 7.59 34 19224 34 19234 7.82 35 19231 35 19241 8.05 36 19238 36 19248 8.28 37 19245 37 19255 8.51 38 19252 38 19262 8.74 39 19259 39 19269 8.97 40 19266 40 19276 9.2 41 19273 41 19283 9.43 42 19280 42 19290 9.66 43 19287 43 19297 9.89 44 19294 44 19304 10.12 45 19301 45 19311 10.35 46 19308 46 19325 10.58 end order value, before (n_id)
I really appreciate your help.
Comment