Announcement

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

  • Merging two datasets in a special way

    Hello,

    I have two datasets which are here below:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int i
      4
      8
     12
     20
     24
     28
     31
     32
     36
     40
     44
     48
     50
     51
     52
     56
     60
     64
     68
     70
     72
     76
     84
     86
     90
     92
     96
    100
    104
    108
    112
    116
    120
    124
    132
    136
    140
    144
    148
    152
    156
    162
    166
    170
    174
    178
    180
    184
    188
    191
    192
    196
    203
    204
    208
    212
    214
    218
    222
    226
    231
    232
    233
    238
    242
    246
    251
    258
    260
    262
    266
    268
    270
    275
    276
    288
    292
    296
    300
    304
    308
    320
    324
    328
    332
    340
    344
    348
    352
    360
    364
    368
    372
    376
    380
    384
    388
    392
    398
    400
    end

    &


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int j
    1511
    1512
    1513
    1514
    1520
    1531
    1532
    1533
    1541
    1542
    1543
    1544
    1549
    1551
    1552
    1553
    1554
    1600
    1711
    1721
    1722
    1723
    1729
    1730
    1810
    1820
    1911
    1912
    1920
    2010
    2021
    2022
    2023
    2029
    2101
    2102
    2109
    2211
    2212
    2213
    2219
    2221
    2222
    2310
    2320
    2330
    2411
    2412
    2413
    2421
    2422
    2423
    2424
    2429
    2430
    2511
    2519
    2520
    2610
    2691
    2692
    2693
    2694
    2695
    2696
    2699
    2710
    2720
    2811
    2812
    2813
    2893
    2899
    2911
    2912
    2913
    2914
    2915
    2919
    2921
    2922
    2923
    2924
    2925
    2926
    2927
    2929
    2930
    3000
    3110
    3120
    3130
    3140
    3150
    3190
    3210
    3220
    3230
    3311
    3312
    end

    I only kept the first 100 observations in each dataset but the point remains the same. I would like to create a new dataset from these two. In the new dataset I want to have all i-j combinations, so in total I will have 100 * 100 observations instead of just 100. So if I sort the new dataset like this (sort i j) then my first 100 observations will have a i values of 4 and j values going from 1511 to 3312. My next 100 observations will have i values of 8 and j values going from 1511 to 3312 and so on.

    Please can you advise me on how to do this.

    Thanks,
    Jad

  • #2
    not completely clear to me but sounds like you want
    Code:
    h cross
    another possibility but I think less likely is
    Code:
    h joinby

    Comment


    • #3
      The cross command did the trick. Thanks!

      Comment

      Working...
      X