Dear Stata community,
I have multiple excel files with data on export. Due to your kind help I managed to save them in dta. They have wide format. I wanted to put them together. Here is a data example of the first file:
Here is my last file:
I put my first dta file to a different folder, opened it and tried to append the rest of the files. I used a code:
I typed:
to spot the mistake
I saw: variable E is str17 in master but double in using data
You could specify append's force option to ignore this string/numeric mismatch. The using variable
would then be treated as if it contained ""
The first file contains export data from Australia to Austria, Belgium and Canada. The second file contains data on export from Asutralia to Switzerland, China and Czech Republic. In the column E in the first file there is: Exports from Australia to Austria - Category - 0112 - Vegetables, horticultural. In the column E in the second file there is: Exports from Australia to Switzerland - Category - 0112 - Vegetables, horticultu
My plan was to save the excel files as dta, append/merge them, change names and reshape.
I have multiple excel files with data on export. Due to your kind help I managed to save them in dta. They have wide format. I wanted to put them together. Here is a data example of the first file:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str4 period double(ExportsfromAustraliatoAustri C D) str17 E "1967" 1.68818291542382 .447193126169174 .254802440348146 "NA" "1968" 1.37783875343941 .255840493746482 .0766597683580703 "NA" "1969" 2.14021372461828 .328313422978159 .1290259660822 ".0011185009753137" "1970" 1.37254388532754 .192041412896288 .103648950063559 ".0014473268885849" "1971" 1.07272091518585 .376749961389412 .150304925135887 ".0043821532603898" "1972" 1.03049032659761 .170154750132609 .0467655443634626 ".0040929481760718" "1973" 1.10660073292803 .554202972554974 .042445121273776 ".0147793837375182" "1974" .619402162186426 .110295313069868 .00421017570778895 ".0033361329234095" "1975" .862150009789141 .457623355172952 .173436807927162 ".005716531769577" "1976" 1.17399480567722 .18227499023391 .0899267099507063 ".0074502711364507" "1977" 1.0596683294864 .252186446517037 .0971412808940711 ".0175952383069712" "1978" 2.74407206961562 .326298100332131 .226576840094671 ".0082933268536468" "1979" 2.43123089502343 .356706683016324 .236905414894377 ".0301890470330195" "1980" 3.73198211321387 .446112989371622 .141884411694923 ".023741354288482" "1981" 2.86560192580854 .11650479750537 .00505486422107316 ".0256636617808451" "1982" 2.46898937574441 .0681212756305846 .0409741067841663 ".0229692068236075" "1983" 1.85716024628491 .171121272324057 .130544004006761 ".0077711427433588" "1984" 1.89950961141022 .55082007656801 .395247194341352 "NA" "1985" 6.74099973156501 4.51314312672418 4.32899960820237 ".0331840324351902" "1986" 2.6416032194799 .922339003082142 .765309045323289 ".0230991871640027" "1987" 3.50108724040966 1.00879296806758 .666709174063678 ".0338925172702406" "1988" 5.89184415767255 4.87417369147086 4.32603952670905 ".0309162835204018" "1989" 2.10293175939197 1.11200655142119 .945336338903254 ".0364085343299939" "1990" 3.09566901071224 .57895066182819 .294643535250431 ".0593818650269951" "1991" 4.5952602023237 2.25751780793534 2.11941353857843 ".0506122384234352" "1992" 5.2282254216153 3.62389907526694 3.2407176217882 ".156218000188867" "1993" 3.60528197241182 2.27059248575925 2.15936564523635 ".0440518674912489" "1994" 4.20129878529848 2.61912210318222 2.48602899558369 ".0897388701919393" "1995" 1.66267308728776 .718284669540413 .601226761357698 ".0763861976604632" "1996" 1.67174006197263 .782547191550645 .713766766181845 ".0226147164761684" "1997" 1.46324874669685 1.14965136733421 1.02237855424437 ".0162570073507562" "1998" 1.49118616589432 1.33347393623139 1.17672043293244 ".126269767485836" "1999" .797078970751392 .71046188236338 .620047433227721 ".0772284463703214" "2000" .685350935246251 .614281599995358 .548381828240676 ".0590893523680979" "2001" .790855012105365 .575420760492461 .517316716681913 ".0434616679209898" "2002" .678040814956461 .572556585585948 .481116637902978 ".0533440622037423" "2003" .962200827340452 .648574348691287 .387374677722107 ".174542912918566" "2004" .539462037877982 .46406333019581 .289660600577625 ".0960438231260797" "2005" .829157935583996 .501237842646939 .0739293580848232 ".198353245480259" "2006" .892993578681696 .297647331955208 .0716496026031399 ".154609313711333" "2007" 1.1831879757206 .330713317689642 .0790955954086102 ".188937995410851" "2008" .722686752070487 .254740682283988 .0355505518170268 ".0736625387465388" "2009" 1.25267905943902 .785066710532028 .0507452481777911 ".529209776576246" "2010" 1.33814239274765 .687448088730707 .101268940320203 ".211859216032929" "2011" 1.89234563458849 .981591215438803 .263935645697609 ".38498013940013" "2012" 1.4661200700721 .764122338527107 .194755663981232 ".135434932164803" "2013" 1.73105339685472 1.04842663639813 .330930068599616 ".0609117081286965" "2014" 1.25397735481203 .851379333036416 .147158715256268 ".108021829853592" "2015" 1.75072124689188 1.39002801113872 .454976523638499 ".0571724831827264" "2016" 1.00536622930604 .584672332418586 .149590925095184 ".195573416796196" end
Here is my last file:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str4 period double(ExportsfromUnitedStatestoIt C D E) "1967" 174.492405064972 166.571163412104 163.87680753628 1.86818219345245 "1968" 212.772665655041 205.116920835749 203.143651495025 1.41942115705834 "1969" 187.473415535854 177.8468516799 175.519416323775 1.58020218845571 "1970" 159.501689171693 152.728422520563 149.485662994443 2.22806510781669 "1971" 219.316793866383 212.531283395739 208.069644029362 3.10099329098794 "1972" 270.925197498744 261.184807999075 255.005775340155 3.19265563767313 "1973" 571.429390196771 542.680836992341 537.037898868968 3.58743498164142 "1974" 602.540700944342 576.921527085956 571.143142451317 3.67182723371965 "1975" 739.625623576642 720.479855816135 712.848206521062 3.38096404656251 "1976" 698.598333363425 664.698702023926 654.810462512371 4.3414671910904 "1977" 626.38505077781 590.68517404259 578.508944325358 6.59111086498766 "1978" 707.119356541337 671.021847169435 660.339622593115 6.39083818051895 "1979" 760.917389007797 712.589239063797 692.958295555045 8.46779806113076 "1980" 895.317486239834 846.317138260775 814.000907854755 12.3003462647501 "1981" 883.322422115479 833.543738107952 814.786509076024 8.90209720803405 "1982" 759.365610232439 714.090520142637 695.033591163977 8.43422504129108 "1983" 533.659510591735 500.947295528265 483.394049428199 9.9052783518371 "1984" 584.432790076 550.831166601927 534.510056497722 10.4122826901857 "1985" 495.466484340692 465.573294246828 444.657679171418 9.60266817579404 "1986" 395.949124094612 370.735126413806 350.832720685255 10.0954907233989 "1987" 408.225920795585 376.992301020841 341.406183969205 14.6507595486822 "1988" 400.573552249945 363.991903597674 324.008880140329 12.8519913744082 "1989" 419.879984081588 385.82343827845 357.327039990317 9.66872036410687 "1990" 563.863921940972 528.636657540521 485.570389834502 14.5067084884993 "1991" 546.737510829842 513.981972839345 464.405146467759 13.2052742268214 "1992" 482.978136748232 457.854628661239 414.090281479538 13.2596704570517 "1993" 437.025421663089 418.59983891854 388.929859931922 9.71452364706735 "1994" 385.604652660188 365.67949377423 316.804193403725 7.16653900104857 "1995" 506.361482618778 486.392741085139 438.858799933078 9.91570730406677 "1996" 534.164608180819 511.960835973455 446.881790915665 10.3896625121043 "1997" 413.522231352292 396.807832148585 351.531171653619 8.27058550983761 "1998" 393.62908124399 376.968391322962 323.987079340289 9.4633523134496 "1999" 302.960938200106 291.03770151843 242.305157729034 10.6523128696524 "2000" 337.140853598744 326.100067225963 275.261443467374 14.3795402551957 "2001" 346.137305082496 331.610729602144 279.270892433107 8.03299700712313 "2002" 373.53086603046 360.9320334875 301.324677101759 9.76703954871962 "2003" 403.608041866262 390.131020594363 300.884640821627 10.5495353952695 "2004" 392.348683165626 376.013171100633 260.509841016342 10.115136571513 "2005" 387.824566283309 367.908243452877 205.361747358679 11.3043293261853 "2006" 357.017444481361 334.653420391861 166.731722546372 7.87347747633133 "2007" 454.614500234626 425.74007272965 289.93387302984 11.1063872689224 "2008" 506.021758199696 476.629636930597 346.473228038767 10.129855797694 "2009" 379.01894106702 357.428543656066 221.380838624052 11.0336506919995 "2010" 422.868504717562 407.076157643286 260.276000878856 7.54702080441411 "2011" 532.33687362881 516.141874286354 335.225999280615 8.73508747063099 "2012" 442.183450698473 416.078377410966 232.345184139121 8.71108087466194 "2013" 598.655032730868 569.010848500849 340.040617334909 5.67700812979672 "2014" 704.419875800654 665.569458856273 364.45370647464 7.47298840585096 "2015" 721.911024339495 684.872741936037 410.692098502934 7.00682387076601 "2016" 677.263848159713 637.861622305507 348.638037618437 5.30732604741538 end
I put my first dta file to a different folder, opened it and tried to append the rest of the files. I used a code:
Code:
global dir "U:\CEPII CHELEM\CHELEM ISIC\All"
clear all
use "U:\CEPII CHELEM\CHELEM ISIC\AUS_AUT BEL CAN.xlsx.dta"
local files : dir "$dir" files "*.dta", respectcase
foreach j in `files' {
append using "$dir/`j'"
}
Code:
set trace on
I saw: variable E is str17 in master but double in using data
You could specify append's force option to ignore this string/numeric mismatch. The using variable
would then be treated as if it contained ""
The first file contains export data from Australia to Austria, Belgium and Canada. The second file contains data on export from Asutralia to Switzerland, China and Czech Republic. In the column E in the first file there is: Exports from Australia to Austria - Category - 0112 - Vegetables, horticultural. In the column E in the second file there is: Exports from Australia to Switzerland - Category - 0112 - Vegetables, horticultu
My plan was to save the excel files as dta, append/merge them, change names and reshape.

Comment