Announcement

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

  • Merging but "year" isn't matching

    Hey everybody,

    I have a problem to which I cannot find an answer to.

    I want to merge two panel datasets which have different ways to show years.

    1.:
    CODE:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str11 year
    "28.06.00"
    "28.07.00"
    "04.08.00"
    "04.01.00"
    "03.01.00"
    "05.01.00"
    "21.06.00"
    "10.01.00"
    "04.02.00"
    "31.01.00"
    "31.01.00"
    "13.01.00"
    "11.02.00"
    "05.01.00"
    "13.01.00"
    "14.02.00"
    "13.01.00"
    "28.02.00"
    "11.01.00"
    "22.02.00"
    "05.03.00"
    "24.02.00"
    "14.01.00"
    "31.03.00"
    "18.08.00"
    "21.09.00"
    "16.06.00"
    "11.01.00"
    "19.04.00"
    "20.01.00"
    "20.01.00"
    "17.01.00"
    "03.03.00"
    "18.01.00"
    "06.01.00"
    "20.01.00"
    "09.03.00"
    "06.01.00"
    "24.01.00"
    "30.01.01"
    "14.01.00"
    "12.01.00"
    "17.01.00"
    "22.03.00"
    "28.02.00"
    "10.03.00"
    "13.01.00"
    "04.08.00"
    "20.03.00"
    "31.01.00"
    "28.06.00"
    "26.01.00"
    "28.06.02"
    "27.06.00"
    "29.12.00"
    "13.03.00"
    "03.03.00"
    "09.03.00"
    "04.02.00"
    "03.02.00"
    "19.05.00"
    "14.03.00"
    "03.02.00"
    "31.03.00"
    "26.07.00"
    "07.02.00"
    "20.03.00"
    "31.03.00"
    "08.02.00"
    "08.02.00"
    "04.04.00"
    "08.02.00"
    "31.03.05"
    "13.04.00"
    "09.08.01"
    "10.03.00"
    "12.05.00"
    "09.02.00"
    "12.05.00"
    "09.02.00"
    "20.04.00"
    "03.05.00"
    "04.04.00"
    "12.04.00"
    "17.01.00"
    "30.06.00"
    "11.02.00"
    "01.06.00"
    "30.06.00"
    "03.01.00"
    "29.11.00"
    "10.02.00"
    "13.06.00"
    "13.09.00"
    "28.02.00"
    "29.03.00"
    "15.02.00"
    "14.02.00"
    "09.05.00"
    "14.02.00"
    end
    2.
    CODE:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year
        .
    14755
    14724
    14734
    15957
    15544
    15210
    16330
    15645
    15474
    17003
    15165
    16651
    16824
    16362
    16814
    16148
    16139
    16285
    17252
    17575
    15804
    16551
    15799
    14990
    15194
    14916
    15622
    18142
    16519
    16337
    16356
    16716
    16895
    16923
    18353
    17241
    17363
    17867
    15714
    15390
    20877
    16785
    17175
    14675
    15792
    19982
    15921
    16565
    16366
    16832
    16218
    16282
    14810
    15400
    16350
    15272
    14699
    20313
    20303
    15691
    18054
    14619
    16985
    16618
    16965
    15307
    16379
    16173
    15124
    15130
    18638
    19278
    15666
    17256
    15354
    15454
    16253
    16867
    15011
    15776
    15818
    16090
    16355
    20795
    14801
    17233
    15186
    16012
    20559
    20444
    15075
    21698
    20830
    17220
    16460
    15887
    17057
    14677
    15753
    end
    format %tdnn/dd/CCYY year
    As you can see, one is a string and the other is an int.

    So I thought, I need to destring the 1. but I get the error:

    CODE:
    Code:
    .         destring year1, generate(year)
    year1: contains nonnumeric characters; no generate
    Note: "year1" is "year" I just renamed it differently

    Has anyone an idea how to match these to year variables, so I can merge them?

    Kind regards,
    Jana

  • #2
    Jana:
    as far as your first file is concerned, you may want to try:
    Code:
    . generate double year_num = date(year, "DM20Y")
    
    . format year_num %td
    
    . list in 1
    
         +----------------------+
         |     year    year_num |
         |----------------------|
      1. | 28.06.00   28jun2000 |
         +----------------------+
    
    .
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment

    Working...
    X