Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Identifying observations with consecutive 3 quarters.

    Dear All, Suppose the data set is:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long com float yq double id
    1 173 505823929
    1 175 505823929
    1 177 505823929
    1 238 506119843
    1 239 506119843
    1 240 506119843
    1 241 506119843
    1 242 506119843
    1 243 506119843
    1 244 506119843
    1 245 506119843
    1 246 506119843
    2 217     50472
    2 218     50472
    2 219     50472
    2 220     50472
    2 221     50472
    2 222     50472
    2 223     50472
    2 224     50472
    2 225     50472
    2 226     50472
    2 227     50472
    2 228     50472
    2 229     50472
    2 230     50472
    2 231     50472
    2 232     50472
    2 233     50472
    2 234     50472
    2 235 504171416
    2 235     50472
    2 236     50472
    2 236 504171416
    2 237 504171416
    2 237     50472
    2 238     50472
    2 239     50472
    2 240     50472
    2 241     50472
    2 242     50472
    2 243     50472
    2 244     50472
    2 245 506119843
    2 245     50472
    2 246     50472
    4 222 504895009
    4 223 504895009
    4 224 504895009
    4 225 504895009
    4 226 504895009
    4 227 504895009
    4 228 504895009
    4 229 504895009
    4 230 504895009
    4 231 504895009
    4 232 504895009
    6 173   5019084
    6 175   5019084
    6 177   5019084
    6 179   5019084
    6 181   5019084
    6 183   5019084
    6 185 505824461
    6 187 505824461
    6 189 505824461
    6 190 505824461
    6 191 505824461
    6 192 505824461
    6 193 505824461
    6 194 505824461
    6 195 505824461
    6 196 505824461
    6 197 505824461
    6 198 505824461
    6 199 505824461
    6 200 505824461
    6 201 505824461
    6 202 505824461
    6 203 505824461
    6 204 505824461
    6 205 505824461
    6 206 505824461
    6 207 505824461
    6 208 505824461
    6 209 505824461
    6 210 505824461
    6 211 505824461
    6 212 505824461
    6 213 505824461
    6 214   5021897
    6 214 505824461
    6 215   5021897
    6 215 505824461
    6 216   5021897
    6 216 505824461
    6 217   5021897
    6 217 505824461
    6 218   5021897
    6 218 505824461
    end
    format %tq yq
    The purpose is, for each shareholder (`id') in each firm (`com'), to construct a dummy, which is 1if the shareholder appears in consecutive 3 quarters (inclduing the current, previous 1 & 2 quarters), 0 otherwise.
    Any suggestions are highly appreciated.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Code:
    by com id (yq), sort: gen wanted = (2*yq - yq[_n-1] - yq[_n-2]) == 3

    Comment


    • #3
      Dear Øyvind, Many thankd for this helpful solution.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment

      Working...
      X