Dear members,
I am writing with respect to the above indicated topic after looking on manuals and FAQ but not finding an exact answer.
I am working on panel data about mutual funds, with monthly information for the time dimension. As part of my filtering analysis, I have isolated panels (i.e. mutual funds) that have at least 12 months of consecutive non-missing values under a specific variable called 'Score' through the tsspell command and some additional functions.
Now, I have one dummy variable ('high_sust') that reports for each of these filtered mutual funds a constant observation each month. The issue is that I would like to replace this observation with a missing value from the month that the funds' consecutive non-missing values under the variable 'Score' terminate (provided that these consecutive observations are >= 12).
I have tried the following code, but get a syntax error, which is most likely related to the max command.
I have tried other alternatives, such as:
My data looks like this (note that the SecId_n present in the code is just a fund identifier that I use for the panel data, PercId is another identifier):
However, I could not come up with a solution, so I thought I would check with the community.
I am writing with respect to the above indicated topic after looking on manuals and FAQ but not finding an exact answer.
I am working on panel data about mutual funds, with monthly information for the time dimension. As part of my filtering analysis, I have isolated panels (i.e. mutual funds) that have at least 12 months of consecutive non-missing values under a specific variable called 'Score' through the tsspell command and some additional functions.
Now, I have one dummy variable ('high_sust') that reports for each of these filtered mutual funds a constant observation each month. The issue is that I would like to replace this observation with a missing value from the month that the funds' consecutive non-missing values under the variable 'Score' terminate (provided that these consecutive observations are >= 12).
I have tried the following code, but get a syntax error, which is most likely related to the max command.
Code:
gen h_sust = high_sust bysort SecId_n: replace h_sust = . if max(Score_cons) >= 12 & Score_cons[_n+1] == . & !missing(PercId)
Code:
bysort SecId_n: replace h_sust = . if Score_cons[_N] >= 12 & Score_cons[_n+1] == . & !missing(PercId)
Code:
* Dataex code
dataex PercId date Score Score_cons high_sust if high_sust == 5
* Example generated by -dataex-. To install: ssc install dataex
clear
input long PercId float date double Score float(Score_cons high_sust)
19 201601 46.92 1 5
19 201602 47.03 2 5
19 201603 47.19 3 5
19 201604 47.16 4 5
19 201605 46.78 5 5
19 201606 46.92 6 5
19 201607 45.98 7 5
19 201608 45.83 8 5
19 201609 45.07 9 5
19 201610 45.31 10 5
19 201611 45.68 11 5
19 201612 45.77 12 5
19 201701 45.73 13 5
19 201702 45.68 14 5
19 201703 45.7 15 5
19 201704 45.55 16 5
19 201705 45.49 17 5
19 201706 45.32 18 5
19 201707 45.14 19 5
19 201708 44.93 20 5
19 201709 44.71 21 5
19 201710 44.9 22 5
19 201711 45.03 23 5
19 201712 44.92 24 5
19 201801 45.14 25 5
19 201802 44.81 26 5
19 201803 44.82 27 5
19 201804 44.71 28 5
19 201805 44.76 29 5
19 201806 45.25 30 5
19 201807 47.09 31 5
19 201808 47.24 32 5
19 201809 47.64 33 5
19 201810 48.09 34 5
19 201811 48.06 35 5
19 201812 47.55 36 5
19 201901 47.55 37 5
19 201902 47.36 38 5
19 201903 47.26 39 5
19 201904 47.41 40 5
19 201905 47.25 41 5
19 201906 47.13 42 5
19 201907 47.48 43 5
19 201908 47.29 44 5
24 201601 46.19 1 5
24 201602 46.35 2 5
24 201603 46.33 3 5
24 201604 . 0 5
24 201605 45.29 1 5
24 201606 . 0 5
24 201607 42.54 1 5
24 201608 42.62 2 5
24 201609 42.56 3 5
24 201610 42.66 4 5
24 201611 42.72 5 5
24 201612 42.68 6 5
24 201701 42.69 7 5
24 201702 42.58 8 5
24 201703 42.56 9 5
24 201704 42.24 10 5
24 201705 41.81 11 5
24 201706 41.65 12 5
24 201707 41.66 13 5
24 201708 41.66 14 5
24 201709 41.57 15 5
24 201710 42.21 16 5
24 201711 42.48 17 5
24 201712 42.28 18 5
24 201801 42.01 19 5
24 201802 41.9 20 5
24 201803 41.78 21 5
24 201804 41.77 22 5
24 201805 41.98 23 5
24 201806 41.73 24 5
24 201807 41.42 25 5
24 201808 41.31 26 5
24 201809 41.04 27 5
24 201810 41.16 28 5
24 201811 41 29 5
24 201812 41.01 30 5
24 201901 40.96 31 5
24 201902 41.14 32 5
24 201903 41.14 33 5
24 201904 41.37 34 5
24 201905 41.82 35 5
24 201906 41.77 36 5
24 201907 41.7 37 5
24 201908 41.7 38 5
94 201601 47.8 1 5
94 201602 47.94 2 5
94 201603 48.17 3 5
94 201604 48.34 4 5
94 201605 47.84 5 5
94 201606 48.75 6 5
94 201607 48.64 7 5
94 201608 48.46 8 5
94 201609 48.28 9 5
94 201610 48.33 10 5
94 201611 48.8 11 5
94 201612 49.59 12 5
end
label values PercId PercDummyId
label def PercDummyId 19 "F000003U5F", modify
label def PercDummyId 24 "F000003YP9", modify
label def PercDummyId 94 "F00000N864", modify
However, I could not come up with a solution, so I thought I would check with the community.
Comment