Announcement

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

  • Importing files from MS Excel

    Dear Stalist,
    I have three excel files, each with a couple of sheets. Here's a sample of one of the sheets:


    Code:
     Country A destination 
    YEAR 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
    ECONOMY
    Algeria 1563237 1701749 2221847 1520025 1755048 3424843 2673738 2591752 4908021 7576592 10597618
    Angola 2459970 3096555 3170485 2463705 3094602 3670213 3319686 3405582 4861987 5228154 10604596
    Benin 20281.54 35515.96 12559.23 4874.743 22440.32 5924.369 954.228 1070.363 968.759 1138.584 393.171
    Botswana 34737.34 40099.9 49928.32 31424.62 38567.74 43125.92 16410.58 26336.76 13996.37 70204.38 143842.3
    Burkina Faso 584.903 2813.854 2613.052 584.699 2845.938 1802.35 3355.192 2114.41 576.229 627.72 1709.629
    Burundi 11726.47 879.747 8431.45 5861.933 3854.118 4315.978 1827.345 542.138 3858.296 2397.226 2195.38
    Cabo Verde 179.497 255.86 146.642 37.887 99.456 1010.093 1206.719 793.669 2608.467 2470.721 1080.366
    Cameroon 34467.36 50011.17 37532.64 36196.56 47549.83 88843.98 67357.39 143410.9 178560.6 223347.7 127443.5
    Central African Republic 774.559 473.624 838.504 1500.817 1294.647 1479.416 1485.974 1369.439 1468.418 7837.409 3761.666
    Chad 6775.873 13920.2 5033.447 14157.17 15926.23 10017.76 13772.41 16487.88 146676.1 1307955 2171454
    Comoros 2276.135 1950.825 1012.192 318.16 1373.064 2307.929 3480.675 3374.191 4289.682 5890.828 870.531
    Congo 226316.7 331103.4 334368.7 285331.6 373497.1 457926 448229.7 212045.4 392777.9 711590.2 1210662
    Côte d'Ivoire 162751.3 348548.9 311367 398229.7 365715.7 299900.4 272718.3 375733.4 389893.7 669242.1 1023795
    Dem. Rep. of the Congo 281699.5 248001.8 329716 208478.4 163612.6 122821.8 97142.7 139245.1 205783 184160.3 395090.4
    Djibouti 6.431 5.222 .. 294.499 37.452 165.069 159.271 416.361 173.612 438.1 322.536
    Egypt 416816 413646.5 432722.5 385429.7 395933.4 565301.3 544114.2 776984 802664.2 917680.1 1483233
    Equatorial Guinea 34424.94 97432.42 41408.77 71830.83 46530.96 135131.9 439758.7 585660.3 971115.9 1346432 1774706
    Eritrea 1630.671 5799.587 1416.098 372.928 380.795 211.282 58.715 345.159 72.909 230.968 427.802
    Eswatini 93194.21 92564.16 105888.3 102589.1 102793.9 79896.93 57078.66 111626.4 262429.9 250776.1 180197.9
    Ethiopia 26726.37 50245 63428.29 45903.38 31768.34 20550.74 21405.11 21962.71 24550 37108.41 51611.38
    Gabon 1741310 2039048 2019245 1157772 1267041 1569563 1340280 1375855 1652595 2169850 3111446
    Gambia 658.362 795.969 207.834 245.453 48.178 127.165 140.435 229.414 20.358 175.925 85.439
    Ghana 192155.3 178103.9 154367.7 151582.7 195433.4 160753.8 178774.5 97213.6 88910.44 145275.2 161244.7
    Guinea 134919.9 161199.6 103551.8 108996.3 101835.8 71848.31 85302.43 64292.75 56133.2 46819.99 58126.57
    How do I import them into a three-dimension panel into Stata?

    Thanks,
    Dapel

  • #2
    I would import one of the sheets into Stata with no headers and then post back the results using dataex.

    Comment


    • #3
      Also, I don't see the third dimension? I see time and country. Perhaps the differing sheets represent the third dimension? Anyway, a starting point would be something like this:
      Code:
      local file1 "somename1"
      local file2 "somename2"
      local file3 "somename3"
      local sheetlist "this that theother"
      save "YourCombinedFile.dta", emptyok
      forval i = 1/3 {
         foreach sheet of local sheetlist {
            clear
            import excel using "`file`i''", sheet("`sheet'")
            append using "YourCombinedFile.dta"
            save "YourCombinedFile.dta", replace
        }      
      }

      Comment


      • #4
        Thank you very much! The 3rd dimension is represented by the name of each of the sheets that make up the three files.

        Comment

        Working...
        X