Hi!

I have the following data set (example seen below) - it contains 66 variables: 8 of these are h_m* (where h_m1 would be the total number of hours in month 1, h_m2 is the total number of hours in month 2 and so on until month 8), 29 are tags d_* (which go from d_1 to d_29) and the remaining 29 variables are number of hours, visit_duration* (these also go from visit_duration1 to visit_duration29).

Code:
input float(h_m1 h_m2 h_m8) double visit_duration1 float d_1 double visit_duration3 float d_3 double visit_duration10 float d_10
. . . 1.5 1 . .   . .
. . .   . . . .   . .
. . .   5 1 5 2 5.5 5
. . .   1 1 4 1 4.5 3
. . .   3 1 2 5   4 4
. . .   8 1 5 2   3 4
. . .   1 1 3 1   3 4
. . . 2.5 1 4 4   4 3
end
I want to sum the total number of hours by month (h_m*) using the 29 visit_duration* variables if the tag's value is equal to the month number. For example, for h_m1 (i.e. month 1) I want to sum the number of hours from any of the visit_duration* variables if its corresponding tag value, d_* is equal to the month number

I have tried using the following code,

Code:
 forvalues i=1/8 {
        forvalues h=1/29 {
            replace h_m`i' = h_m`i' + visit_duration`h' if d_`h'==`i'
      }
 }
but I am not getting the results I want, when I run it all I see is:

Code:
0 real changes made

I tried using egen before, but from what I saw on this forum, it wasn't a good idea at all. Any suggestions are welcome. I apologize if the post is confusing, it is hard to explain something in English when it isn't my first language. I would be happy to try and explain more if it wasn't clear. Thanks!