Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: Read csv in Stata
From
Haluk Vahaboglu <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: Read csv in Stata
Date
Mon, 21 Oct 2013 13:35:10 +0000
Dear Nikos,
In linux I opened terminal in the directory where x.csv is in and typed "cat x.csv | sed -e 's/\""/\"/g' -e 's/^"//g' -e 's/"$//g'>xx.csv" to get an output xx.csv file. This is working flawlessly.
Next option, I opened x.csv in open office writer saved as text file and after calling the find&replace with ctrl+H typed (^") to select leading quotes and left replace empty to remove leading quotes; similarly typed ("$) in find line for the quotes before the return sign and later typed ("") in find and replaced with (") single quotes. All these were done with regular expression option of find&replace checked.
In windows probably you may find a solution in word-regular expression find replace options but ı am not sure of any command line option.
Hope this is useful.
Prof. Dr. Haluk Vahaboglu
Kadıkoy / Istanbul TURKIYE
----------------------------------------
> Date: Mon, 21 Oct 2013 13:56:30 +0100
> From: [email protected]
> Subject: st: Read csv in Stata
> To: [email protected]
>
>
> Dear all,
>
> I have a set of csv files which I want to read into Stata. Their first two lines are:
>
> Year,Reporter Code,Trade Flow Code,Partner Code,Classification,Commodity Code,Quantity Unit Code,Supplementary Quantity,Netweight (kg),Value,Estimation Code
> "2005,826,1,0,""H2"",""030211"",8,461906,461906,2554127,0"
>
> Unfortunately in order to use insheet the second line must become
> 2005,826,1,0,"H2","030211",8,461906,461906,2554127,0
>
> ie lose leading and ending double quotes and replace the double double quotes with double quotes.
>
> To do these I use a text editor, but because the files have many observations this takes too long.
> Do you have any idea of how I can do that faster and preferably in Stata.
>
> Thanks for your time.
> All the best,
> Nikos
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/