dear statalisters,
I am brand new to stata and regarding a classwork at my university I've got to calculate market equity (shares price x shares outstanding) from a dataset which looks like this:
prc vol ret shrout monthdt
35 39 1259 1972m4
33 298 -.057142857 1259 1972m5
28.25 271 -.143939391 1259 1972m6
26 279 -.079646021 1259 1972m7
21.75 322 -.163461536 1259 1972m8
21.25 205 -.022988506 1259 1972m9
20.875 114 -.01764706 1259 1972m10
19.875 420 -.047904193 1259 1972m11
25 840 .257861644 1259 1972m12
20 691 -.200000003 1259 1973m1
20.5 401 .025 1259 1973m2
18.5 380 -.097560972 1259 1973m3
15.5 121 -.162162155 1259 1973m4
-14.125 306 -.088709675 1259 1973m5
-14.437 203 .022123894 1259 1973m6
15.125 215 .047619049 1259 1973m7
-12.81 145 -.15289256 1259 1973m8
15.5 346 .209756091 1259 1973m9
14.5 234 -.062903225 1259 1973m10
-11.18 297 -.228448272 1259 1973m11
10 341 -.106145248 1259 1973m12
-10.875 67 .090000004 1259 1974m1
9.875 40 -.091954023 1259 1974m2
11.87 188 .202531651 1259 1974m3
10 145 -.15578948 1259 1974m4
-10.43 132 .043749999 1259 1974m5
9.625 161 -.077844314 1259 1974m6
However, the market equity needed has to be from june (t-1) and then matched to monthly returns from July (t) through June (t+1), i.e. after generating the variable for market equity and copying every june (t-1) observation for the entire year I would then need to lag it 13 months so that it matches the returns starting from July (t) for a year.
Nevertheless that data is vastly extensive and usually not consistent because I have to also take account the id of the security that sometimes doesn't report observations for a consistent time frame.
This is my codeline so far:
replace prc = abs(prc)
generate month=month(date)
generate maeq = prc*shrout if month==6
replace maeq = maeq[_n-1] if missing(maeq)
generate lagmaeq = maeq[_n-13]
the code works well, however I don't get the desired results and I think that I am not taking into account the id of the security and just lagging the maeq for june. I guess that is a problem because then other securities could be assigned with maeq from the previous security.
I am struggling on this problem for an entire day now. How do you think I could account for this issue?
I really appreciate any help you could give me,
Best,
Thom
I am brand new to stata and regarding a classwork at my university I've got to calculate market equity (shares price x shares outstanding) from a dataset which looks like this:
prc vol ret shrout monthdt
35 39 1259 1972m4
33 298 -.057142857 1259 1972m5
28.25 271 -.143939391 1259 1972m6
26 279 -.079646021 1259 1972m7
21.75 322 -.163461536 1259 1972m8
21.25 205 -.022988506 1259 1972m9
20.875 114 -.01764706 1259 1972m10
19.875 420 -.047904193 1259 1972m11
25 840 .257861644 1259 1972m12
20 691 -.200000003 1259 1973m1
20.5 401 .025 1259 1973m2
18.5 380 -.097560972 1259 1973m3
15.5 121 -.162162155 1259 1973m4
-14.125 306 -.088709675 1259 1973m5
-14.437 203 .022123894 1259 1973m6
15.125 215 .047619049 1259 1973m7
-12.81 145 -.15289256 1259 1973m8
15.5 346 .209756091 1259 1973m9
14.5 234 -.062903225 1259 1973m10
-11.18 297 -.228448272 1259 1973m11
10 341 -.106145248 1259 1973m12
-10.875 67 .090000004 1259 1974m1
9.875 40 -.091954023 1259 1974m2
11.87 188 .202531651 1259 1974m3
10 145 -.15578948 1259 1974m4
-10.43 132 .043749999 1259 1974m5
9.625 161 -.077844314 1259 1974m6
However, the market equity needed has to be from june (t-1) and then matched to monthly returns from July (t) through June (t+1), i.e. after generating the variable for market equity and copying every june (t-1) observation for the entire year I would then need to lag it 13 months so that it matches the returns starting from July (t) for a year.
Nevertheless that data is vastly extensive and usually not consistent because I have to also take account the id of the security that sometimes doesn't report observations for a consistent time frame.
This is my codeline so far:
replace prc = abs(prc)
generate month=month(date)
generate maeq = prc*shrout if month==6
replace maeq = maeq[_n-1] if missing(maeq)
generate lagmaeq = maeq[_n-13]
the code works well, however I don't get the desired results and I think that I am not taking into account the id of the security and just lagging the maeq for june. I guess that is a problem because then other securities could be assigned with maeq from the previous security.
I am struggling on this problem for an entire day now. How do you think I could account for this issue?
I really appreciate any help you could give me,
Best,
Thom
Comment