I'm currently trying to merge two different datasets. I receive the following error from Stata:
variable date is str10 in master but long in using data
You could specify merge's force option to ignore this string/numeric mismatch. The using variable would then be treated as if it contained "".
So the problem is that in my main data file the variable date is: 09/15/2008 and in the second file the variable date is: 15sep2008, which Stata sees as 17790 (see second column of the second dataset). I want to change the variable date from the main data file to match with the file I want to merge. How can I change the 09/15/2008 to 15sep2008?
I'm using the following data:
Data from the main document
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str10 date int time float(open high low close) long volume str9 ticker "09/15/2008" 1559 21.49 21.49 21.43 21.44 29040 "A" "09/15/2008" 1558 21.52 21.52 21.47 21.49 15346 "A" "09/15/2008" 1557 21.52 21.53 21.5 21.52 22400 "A" "09/15/2008" 1556 21.55 21.55 21.52 21.52 23300 "A" "09/15/2008" 1555 21.52 21.54 21.5 21.54 15197 "A" "09/15/2008" 1554 21.48 21.53 21.47 21.52 19552 "A" "09/15/2008" 1553 21.43 21.51 21.42 21.47 17282 "A" "09/15/2008" 1552 21.44 21.45 21.39 21.44 27300 "A" "09/15/2008" 1551 21.47 21.47 21.43 21.44 14062 "A" "09/15/2008" 1550 21.52 21.52 21.47 21.48 12443 "A" "09/15/2008" 1549 21.52 21.54 21.5 21.52 8000 "A" "09/15/2008" 1548 21.51 21.54 21.49 21.52 8200 "A" "09/15/2008" 1547 21.51 21.57 21.5 21.51 8400 "A" "09/15/2008" 1546 21.53 21.54 21.49 21.49 12462 "A" "09/15/2008" 1545 21.55 21.55 21.51 21.53 8600 "A" "09/15/2008" 1544 21.52 21.6 21.52 21.56 14600 "A" "09/15/2008" 1543 21.55 21.58 21.53 21.53 11800 "A" "09/15/2008" 1542 21.58 21.6 21.55 21.55 10900 "A" "09/15/2008" 1541 21.57 21.59 21.53 21.58 18200 "A" "09/15/2008" 1540 21.53 21.55 21.49 21.54 54836 "A" "09/15/2008" 1539 21.55 21.55 21.53 21.53 13200 "A" "09/15/2008" 1538 21.54 21.55 21.54 21.55 27500 "A" "09/15/2008" 1537 21.54 21.56 21.54 21.54 11551 "A" "09/15/2008" 1536 21.54 21.55 21.54 21.55 12100 "A" "09/15/2008" 1535 21.59 21.61 21.54 21.54 22513 "A" "09/15/2008" 1534 21.54 21.64 21.54 21.59 30900 "A" "09/15/2008" 1533 21.57 21.57 21.53 21.54 11324 "A" "09/15/2008" 1532 21.56 21.57 21.54 21.57 6400 "A" "09/15/2008" 1531 21.54 21.57 21.53 21.57 8642 "A" "09/15/2008" 1530 21.52 21.56 21.51 21.55 12407 "A" "09/15/2008" 1529 21.49 21.53 21.47 21.53 9900 "A" "09/15/2008" 1528 21.54 21.54 21.48 21.49 8300 "A" "09/15/2008" 1527 21.57 21.57 21.53 21.53 2800 "A" "09/15/2008" 1526 21.56 21.57 21.54 21.57 4700 "A" "09/15/2008" 1525 21.49 21.57 21.49 21.55 11800 "A" "09/15/2008" 1524 21.52 21.55 21.49 21.49 8600 "A" "09/15/2008" 1523 21.55 21.56 21.52 21.52 8370 "A" "09/15/2008" 1522 21.55 21.57 21.54 21.54 3655 "A"
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double permno long date str8 ticker str36 comnam double(bidlo askhi prc bid ask openprc) 10145 17790 "HON" "HONEYWELL INTERNATIONAL INC" 45.77000045776367 46.9900016784668 45.91999816894531 45.970001220703125 46 46.31999969482422 10516 17790 "ADM" "ARCHER DANIELS MIDLAND CO" 22.56999969482422 23.760000228881836 22.760000228881836 22.799999237060547 22.809999465942383 23.280000686645508 11891 17790 "MGM" "M G M MIRAGE" 29.030000686645508 31.290000915527344 29.829999923706055 29.540000915527344 29.559999465942383 29.68000030517578 11896 17790 "" "MAXIM INTEGRATED PRODUCTS INC" . . . . . . 13856 17790 "PEP" "PEPSICO INC" 72.08000183105469 73.55999755859375 72.3499984741211 72.43000030517578 72.5199966430664 72.08000183105469 13901 17790 "MO" "ALTRIA GROUP INC" 20.510000228881836 21.100000381469727 20.90999984741211 20.969999313354492 20.969999313354492 20.649999618530273 13928 17790 "COP" "CONOCOPHILLIPS" 68.5999984741211 72.54000091552734 68.72000122070313 68.7699966430664 68.79000091552734 70.48999786376953 14541 17790 "CVX" "CHEVRON CORP NEW" 80.08999633789063 83.80000305175781 80.08999633789063 80.55999755859375 80.56999969482422 81.16000366210938 14593 17790 "AAPL" "APPLE INC" 140.36000061035156 147.69000244140625 140.36000061035156 140.60000610351562 140.77999877929687 142.02999877929687 14702 17790 "AMAT" "APPLIED MATERIALS INC" 15.880000114440918 16.65999984741211 16.34000015258789 16.34000015258789 16.350000381469727 15.899999618530273 15069 17790 "MRO" "MARATHON OIL CORP" 40.75 44.52000045776367 40.81999969482422 41.13999938964844 41.20000076293945 41.560001373291016 15579 17790 "TXN" "TEXAS INSTRUMENTS INC" 21.6200008392334 22.350000381469727 21.90999984741211 21.93000030517578 21.959999084472656 21.639999389648438 17830 17790 "UTX" "UNITED TECHNOLOGIES CORP" 62.52000045776367 64.12000274658203 63.119998931884766 63.20000076293945 63.290000915527344 62.83000183105469 21020 17790 "AMR" "A M R CORP DEL" 10.460000038146973 12.140000343322754 11.300000190734863 11.289999961853027 11.369999885559082 10.890000343322754 21776 17790 "EXC" "EXELON CORP" 65.55000305175781 67.91000366210938 66.5999984741211 66.61000061035156 66.6500015258789 66.94000244140625 22779 17790 "MOT" "MOTOROLA INC" 7.650000095367432 8.09000015258789 7.650000095367432 7.659999847412109 7.670000076293945 8.050000190734863 24643 17790 "AA" "ALCOA INC" 26.479999542236328 28.329999923706055 26.93000030517578 27.040000915527344 27.049999237060547 27.700000762939453 25320 17790 "CPB" "CAMPBELL SOUP CO" 38.43000030517578 39.869998931884766 39.20000076293945 39.09000015258789 39.22999954223633 38.689998626708984 25785 17790 "F" "FORD MOTOR CO DEL" 4.5 5.070000171661377 4.739999771118164 4.78000020980835 4.789999961853027 4.610000133514404 26382 17790 "MEE" "MASSEY ENERGY CO" 36.5099983215332 42.369998931884766 37.349998474121094 37.36000061035156 37.41999816894531 41.380001068115234 26607 17790 "SNS" "STEAK N SHAKE CO" 7.039999961853027 7.510000228881836 7.170000076293945 7.179999828338623 7.199999809265137 7.489999771118164 27422 17790 "CLF" "CLEVELAND CLIFFS INC" 71.13999938964844 84.47000122070313 73.0999984741211 73.22000122070313 73.30000305175781 77.04000091552734 27959 17790 "DUK" "DUKE ENERGY CORP NEW" 17.65999984741211 18.40999984741211 17.860000610351563 17.8799991607666 17.899999618530273 17.65999984741211 37284 17790 "TSO" "TESORO CORP" 15.619999885559082 17.799999237060547 15.979999542236328 15.989999771118164 16.020000457763672 17.5 39087 17790 "S" "SPRINT NEXTEL CORP" 6.690000057220459 7.28000020980835 6.78000020980835 6.800000190734863 6.789999961853027 7.070000171661377 46886 17790 "KLAC" "K L A TENCOR CORP" 32.2400016784668 33.310001373291016 32.29999923706055 32.29999923706055 32.310001373291016 32.369998931884766 46922 17790 "RAD" "RITE AID CORP" .949999988079071 1.100000023841858 1 1.0199999809265137 1 .9800000190734863 48020 17790 "FOH" "FREDERICKS HOLLYWOOD GROUP INC" .8700000047683716 .8700000047683716 .8700000047683716 .8500000238418579 .9700000286102295 .8700000047683716 50876 17790 "LLY" "LILLY ELI & CO" 45.66999816894531 46.7400016784668 46.040000915527344 46.11000061035156 46.119998931884766 45.849998474121094 51692 17790 "PIR" "PIER 1 IMPORTS INC DE" 4.099999904632568 4.5 4.239999771118164 4.269999980926514 4.289999961853027 4.099999904632568 53613 17790 "MU" "MICRON TECHNOLOGY INC" 4.329999923706055 4.909999847412109 4.340000152587891 4.349999904632568 4.360000133514404 4.909999847412109 59010 17790 "GPS" "GAP INC" 18.690000534057617 19.84000015258789 19.1200008392334 19.15999984741211 19.15999984741211 18.690000534057617 61241 17790 "AMD" "ADVANCED MICRO DEVICES INC" 5.179999828338623 5.630000114440918 5.179999828338623 5.190000057220459 5.199999809265137 5.309999942779541 61399 17790 "LOW" "LOWES COMPANIES INC" 24.260000228881836 25.440000534057617 24.520000457763672 24.520000457763672 24.530000686645508 24.360000610351563 61621 17790 "PAYX" "PAYCHEX INC" 33.15999984741211 34.25 33.18000030517578 33.16999816894531 33.209999084472656 33.59000015258789 62148 17790 "CSX" "C S X CORP" 57.869998931884766 61.810001373291016 58.470001220703125 58.119998931884766 58.689998626708984 59.529998779296875 63467 17790 "BRO" "BROWN & BROWN INC" 19.899999618530273 21.239999771118164 20.3700008392334 20.420000076293945 20.43000030517578 20.65999984741211 64629 17790 "MDR" "MCDERMOTT INTERNATIONAL INC" 27.049999237060547 29.940000534057617 27.610000610351563 27.670000076293945 27.68000030517578 29.940000534057617
Best regards,
Johnson
0 Response to How to change string data to numeric data in Stata
Post a Comment