Announcement

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

  • set quarterly dates

    Dear All, I have this dataset,
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long id float(year INV3 ROA)
    1 172  -.0045871646    .0933
    1 173    -.01167711    .1583
    1 174   -.006433757  .175187
    1 175   -.012181344    .2364
    1 176    -.01321603   .10577
    1 177    -.01422899    .1441
    1 178    -.02282987    .2075
    1 179    -.05133751  .145931
    1 180    .009771403     .076
    1 181    .025396004    .0761
    1 182    .025864497    .1725
    1 183     .03664489    .1458
    1 184    -.05361909     .101
    1 185   -.032001555    .1993
    1 186   -.033957694      .38
    1 187   -.033961434  .539616
    1 188   -.012766922  .195137
    1 189   -.008193411    .3912
    1 190   -.027836805    .6234
    1 191    -.03327792    .8644
    1 192   -.014817852    .2636
    1 193   -.032159634    .5398
    1 194   -.068282396    .8355
    1 195    -.05946866    .1485
    1 196   -.004816948    .2252
    1 197    .003146131    .4551
    1 198    .010677342    .7072
    1 199   -.026609255    .9472
    1 200   -.010889765    .2613
    1 201  -.0029442655  .500428
    1 202    -.01105878    .7497
    1 203    -.02014889    .9554
    1 204   -.009636433     .313
    1 205    -.02543132    .5991
    1 206   -.028388817    .8006
    1 207     .00702387   1.0465
    1 208   -.009761282    .2662
    1 209   -.016195519    .4998
    1 210   -.026507244    .7564
    1 211    -.04981959    .9433
    1 212    -.02229787      .21
    1 213   -.035000585  .438673
    1 214    -.05158117    .6756
    1 215     -.0459952  .870771
    1 217   -.007121075    .5001
    1 218   -.013362974  .777682
    1 220    -.00987949    .2507
    1 221   -.019417563    .4871
    1 222    -.01337445    .7414
    1 223    -.03838065    .9317
    1 224    -.03535081    .2346
    1 226   -.034809645    .7066
    1 228   -.015703905    .2085
    1 229    -.01893671    .4153
    1 230   -.005885932    .6289
    1 231   -.011122453    .7478
    1 232   .0009650833    .2002
    1 233     .01975026    .4042
    1 234    .022063773    .6198
    1 225    -.04423483    .4631
    1 227   -.034652203    .8277
    1 219    -.02491837    .9711
    1 216    .003842445    .2534
    2 172  -.0005397516    .4792
    2 173 -.00009546917   2.3655
    2 174   -.001805673 2.980188
    2 175  -.0006784464   6.0275
    2 176  -.0001906369  .984299
    2 177  -.0016465855   2.8043
    2 178  -.0016093967   3.0185
    2 179    -.02953893 6.994731
    2 180   -.026658617   1.4801
    2 181   -.027429914   4.7261
    2 182    -.02314766   4.8409
    2 183   -.017176721   7.6395
    2 184   -.020411134   1.7772
    2 185    -.01661057   5.0345
    2 186    -.02278793   4.5347
    2 187   -.031086253 6.548739
    2 188   -.016051646 1.231006
    2 189    -.03447536   3.1708
    2 190     -.0213942   2.8846
    2 191     -.0459969   7.0893
    2 192   -.015317387    .7196
    2 193    -.02312829   2.1844
    2 194    -.01753936    2.378
    2 195   -.023852894   4.2309
    2 196  .00012526485    .7281
    2 197    .001261712   2.5437
    2 198  -.0020973925   2.9509
    2 199    -.03045349   5.0069
    2 200   -.009536654    .8223
    2 201  -.0035895896 2.120494
    2 202   -.008612886   2.3503
    2 203   -.010163626   5.0048
    2 204  -.0004300943    .5277
    2 205    -.01190996   1.3649
    2 206   -.011792352   1.6463
    2 207   -.019083075   4.5325
    2 208  -.0005459896    .5046
    end
    format %tq year
    label values id id
    label def id 1 "000001", modify
    label def id 2 "000002", modify
    which I'd like to use (ssc install) -xtbalance- command to construct a balanced panel data set, say from `2003q1' (172) to '2010q1' (200). The command is
    Code:
    xtset id year
    xtbalance, range(172 200) miss(INV3 ROA)
    My question is if 172 and 200 in range(172,200) can be substituted by a formal Stata format (human readable). I note that the following does not work.
    Code:
    xtset id year
    xtbalance, range(2003q1 2010q1) miss(INV3 ROA)
    Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Look at the help and then -- in case the help understates what can be done -- look at the code The syntax statement explains that the range() option expects precisely two integers and the first must be smaller. No flexibility there.

    Code:
    syntax , Range(numlist min=2 max=2 int ascending) [Miss(varlist)]
    Naturally you can always do things like

    Code:
     
     xtbalance, range(`=yq(2003, 1)' `=yq(2010,1)') miss(INV3 ROA)
    because Stata evaluates the expressions before xtbalance gets to work.

    Incidentally I note that

    1. year is a fairly poor choice of name for a quarterly date variable. That wasted a few seconds of my time, and a few more in pointing this out.

    2. xtbalance includes as a subroutine xtpattern, written by myself and on SSC, without a word of mention in the help. I say: poor practice. Use someone else's code by all means -- so long as you flag that.

    Comment


    • #3
      Dear Nick, Thanks for the suggestions. The data set was from someone else. I agree that `year' is a poor choice (I noticed that).
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment

      Working...
      X