Hi,
I am at a complete loss. I have a dataset with dates in the format %td (variable name: månedhunt2lq2). I want to change them to only include month and year, as I am comparing them to a dataset that only include month and year, not the date. Those dates are in the format %tm (seen as eg "2007m5). I tried this code: "format månedhunt2lq2 %tm", but that completely changed the dates. For example, 31jan1997 (13545days since 01jan1960) changed into 3088m10. I then tried a code I found elsewhere on this forum: "gen month = month(dofm( månedhunt2lq2 ))" & also "gen year = year(dofm( månedhunt2lq2 ))". This also gives 10 (october) and year 3088. I think it happens because STATA then count 13545 months since jan 1960, but I really don't know how to procede.
I am at a complete loss. I have a dataset with dates in the format %td (variable name: månedhunt2lq2). I want to change them to only include month and year, as I am comparing them to a dataset that only include month and year, not the date. Those dates are in the format %tm (seen as eg "2007m5). I tried this code: "format månedhunt2lq2 %tm", but that completely changed the dates. For example, 31jan1997 (13545days since 01jan1960) changed into 3088m10. I then tried a code I found elsewhere on this forum: "gen month = month(dofm( månedhunt2lq2 ))" & also "gen year = year(dofm( månedhunt2lq2 ))". This also gives 10 (october) and year 3088. I think it happens because STATA then count 13545 months since jan 1960, but I really don't know how to procede.
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input float(månedhunt2lq2 month year)
13545 10 3088
13654 11 3097
13732 5 3104
13178 3 3058
13728 1 3104
13426 11 3078
13262 3 3065
13107 4 3052
13492 5 3084
13612 5 3094
13254 7 3064
13464 1 3082
13412 9 3077
13621 2 3095
. . .
13149 10 3055
13550 3 3089
13419 4 3078
. . .
13077 10 3049
12833 6 3029
13277 6 3066
13086 7 3050
13674 7 3099
13119 4 3053
13151 12 3055
13314 7 3069
. . .
13305 10 3068
. . .
13171 8 3057
13502 3 3085
13473 10 3082
13548 1 3089
. . .
13295 12 3067
. . .
13045 2 3047
13128 1 3054
13171 8 3057
13420 5 3078
13312 5 3069
13747 8 3105
13084 5 3050
13092 1 3051
13591 8 3092
. . .
13131 4 3054
13157 6 3056
13681 2 3100
13676 9 3099
13041 10 3046
. . .
13412 9 3077
13325 6 3070
12810 7 3027
. . .
13193 6 3059
13448 9 3080
13179 4 3058
13033 2 3046
13225 2 3062
13232 9 3062
13559 12 3089
. . .
. . .
. . .
13189 2 3059
13419 4 3078
. . .
13089 10 3050
13204 5 3060
13129 2 3054
13536 1 3088
13490 3 3084
. . .
. . .
13292 9 3067
. . .
13095 4 3051
13585 2 3092
13036 5 3046
13226 3 3062
13125 10 3053
13591 8 3092
13231 8 3062
13565 6 3090
13539 4 3088
13067 12 3048
13118 3 3053
13199 12 3059
13468 5 3082
13414 11 3077
13204 5 3060
13660 5 3098
13530 7 3087
13169 6 3057
. . .
13031 12 3045
13537 2 3088
end
format %td månedhunt2lq2

Comment