Hi I will sincerely appreciate if someone can help with the below issue: I have the attached dataset snaphot of which is as below. I want to compute a variable that for each row first takes the value of cumafd_h, divides this into current and all the lagged values of afd_h, multiplies by the correspding value of mb_h (current when takes the current afd_h and lagged when takes lagged afd_h), and then sums the entire series. I want to do this for alll the rows and by gvkey. For example: - for the 3rd row (gvkey 1000, fyear 1972), the variable needs to be compuated as 1.38*(-7.05/-6.86)+1.30*(.19/-6.86)+1.42*((.)/(-6.86)) - for the 4th row (gvkey 1000, fyear 1973), the variable needs to be compuated as 0.82*(-0.37/-7.23))+1.38*(-7.05/-7.23)+1.30*(.19/-7.23)+1.42*((.)/(-7.23)) I also want to impose the restriction that whenever the value within the parrenthesis is <0 , the it is resert as 0. For example - for the 4th row, (.19/-7.23) needs to be reset to 0. This variable also needs to be computed by group gvkey. My apologies if it is a lot of work. gvkey fyear mb_h afd_h cumafd_h 1000 1970 1.42 1000 1971 1.30 0.19 0.19 1000 1972 1.38 -7.05 -6.86 1000 1973 0.82 -0.37 -7.23 1000 1974 0.79 -0.48 -7.71 1000 1975 0.92 -1.08 -8.79 1000 1976 0.93 9.19 0.40 1000 1977 1.07 5.16 5.56 1001 1983 2.28 1001 1984 1.25 0.27 0.27 1001 1985 1.68 17.24 17.51 1002 1972 0.75 1003 1983 1.94 1003 1984 1.11 -0.25 -0.25
... View more