Announcement

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

  • Converting CSV file to Excel and then uploading it into Stata format

    https://www.eia.gov/beta/internation...=2014&end=2016

    Hi,

    I would like to convert the above file into excel and then to Stata format. I tried accessing this data set but was unable to convert it into Stata. In addition, how do I narrow the number of countries I want to analyse in terms of only analysing the top 20 oil producing countries? Thank you.

  • #2
    You just download the csv and drop it in the same directory as your do-file, then type
    Code:
    insheet using "International_data.csv", comma clear

    Comment


    • #3
      I followed the link, and there is not data file there.

      What Justin explained is the correct approach, it is easier to import data in Stata from csv or tab delimited files, rather than excel files. In fact there are restrictions on the file size of excel file of something like 60mb, and there are no such restrictions on csv and tab delimited files.

      To answer your second question, you need to be on clear how you define "the top 20 oil producing countries".

      Comment


      • #4
        I followed the link and clicked on the download option. Not sure if I downloaded the correct data, but here's how you can get the top 20 countries from that downloaded dataset.

        Code:
        insheet using International_data.csv, comma clear
        drop v1 v3 
        
        rename (v2 v4 v5 v6) (country v2014 v2015 v2016)
        drop in 1/10 
        
        destring v* , replace ignore("-")
        
        gsort -v2016
        gen rank = _n 
        
        keep if rank <= 20
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str36 country double(v2014 v2015 v2016) float rank
        "Russia"               10107.087671233 10252.854794521  10551.49726776  1
        "Saudi Arabia"         9735.3424657534 10168.246575342 10460.710382514  2
        "United States"        8758.5998630137 9430.6520876712 8830.6721393443  3
        "Iraq"                 3368.0410958904 4045.0410958904 4443.5163934426  4
        "Iran"                 3239.0684931507 3293.1890410959 4151.1666666667  5
        "China"                4208.2547945205 4277.6931506849  3980.650273224  6
        "Canada"               3613.2246575342 3677.1260273973 3679.0464480874  7
        "United Arab Emirates" 3010.1917808219 3149.4520547945  3242.650273224  8
        "Kuwait"               2642.0547945205 2783.6712328767  2904.825136612  9
        "Brazil"               2254.6003068493 2437.4449013699 2515.4590163934 10
        "Venezuela"                       2500            2500 2276.9672131148 11
        "Mexico"               2468.5479452055 2302.4931506849 2186.8743169399 12
        "Nigeria"              2347.1780821918 2171.1616438356 1871.2049180328 13
        "Angola"               1741.6164383562 1801.8630136986 1769.6147540984 14
        "Norway"               1562.1835616438 1610.2712328767 1647.9754098361 15
        "Kazakhstan"           1632.0767123288 1653.0547945205 1595.1994535519 16
        "Qatar"                1537.4246575342            1498 1495.9016393443 17
        "Algeria"                         1420            1429 1348.3606557377 18
        "Oman"                 943.47964109589 981.97242465753  1006.840568306 19
        "United Kingdom"              787.2186 893.26014520548 933.02254371585 20
        end

        Comment

        Working...
        X