Announcement

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

  • Unzip gzip csv file from within stata

    Hi all,

    I've done a fair amount of searching and couldn't find anything so I worry that this is a futile attempt, but I thought I'd give it one last shot on here: does anybody know of a way for me to unzip gzipped csv (.gz) files from within Stata? I have access to a lot of these that are stored on a remote server and for some very unfortunate reason, I can only access them through Stata (and not the linux shell) at the moment.

    Just to clarify, I am wondering whether something like unzipfile exists that can handle .gz files. I'm aware of gzuse and gzsave but the underlying files are .csv and not .dta unfortunately.

    Any help would be highly appreciated!

  • #2
    From within Stata,
    Code:
    shell gunzip filename.gz
    should run the linux gunzip command in your linux shell producing an unzipped file.
    Code:
    . dir
    
    total 8
    -rw-r--r--  1 lisowskiw  staff  3054 Jun 16 15:23 auto.dta.gz
    
    . shell gunzip *.gz
    
    
    . dir
    
    total 32
    -rw-r--r--  1 lisowskiw  staff  12765 Jun 16 15:23 auto.dta
    
    .

    Comment


    • #3
      oh of course! Thanks so much William Lisowski

      Comment


      • #4
        Hi William Lisowski,

        I'm trying to extract a CSV excel from a zip folder with a .gz extension -downloaded from here.

        I tried the two codes below, nevertheless, I was unable to extract the file from the zip folder, appreciate your help and thoughts.

        1- using
        Code:
        gunzip
        Code:
          
         shell gunzip filename.gz


        2- I tried to change the zip extension from .gz to .zip/.rar using windows shell, and then use the
        Code:
        unzipfile
        command for .zip folder, and used
        Code:
        shell
        for .rar folder
        Code:
        shell ren "filename.gz" "filename.zip"
        unzipfile filename.zip, replace
        Code:
        shell ren "filename.gz" "filename.rar"
        shell set path="C:\Program Files\WinRAR";%path% & unrar  e "filename.rar"


        The error I'm receiving is the following:
        Code:
        zip END header not found
        
        extracting filename.zip incomplete
        Code:
        
        


        Thank you,

        Comment


        • #5
          Don't rename the file. For WinRAR, just leave the filename as-is. The following works for me.
          Code:
          clear *
          copy "https://www.ilo.org/ilostat-files/WEB_bulk_download/indicator/SDG_0131_SEX_SOC_RT_A.csv.gz" "`c(pwd)'/SDG_0131_SEX_SOC_RT_A.csv.gz
          shell "C:\Program Files\WinRAR\winrar.exe" e `c(pwd)'/SDG_0131_SEX_SOC_RT_A.csv.gz
          import delimited SDG_0131_SEX_SOC_RT_A.csv
          list in 1, noobs string(50)
          I think that gunzip is for machines running under a Linux operating system. From your post, you seem to be using Windows.

          Comment

          Working...
          X