I have all .xlsx files in a folder.
I am trying to clean the data with simple commands.
I could successfully do it one file by one.
My command is below:
//
import delimited "C:\Users\phh84\Google Drive\Data\barley_2016.csv", clear
keep year period state agdistrict county commodity dataitem value
export excel using "C:\Users\phh84\Google Drive\Data\cleaned data\barley_2016.xlsx", sheet("forgams") sheetreplace firstrow(variables)
//
So I'm trying to do all the files in this folder. I tried below command:
//
local files : dir "C:\Users\phh84\Google Drive\Data\cleaned data" files "*.xlsx"
cd "C:\Users\phh84\Google Drive\Data\cleaned data"
foreach file in `files' {
import delimited `file', clear
qui keep year period state agdistrict county commodity dataitem value
qui export excel using 'file', sheet("forgams") sheetreplace firstrow(variables) replace
}
//
I get below error message.
I don't know why I get this error.
Note: 431 binary zeros were ignored in the source file. The first instance occurred on line 1. Binary zeros are not valid in text data.
Inspect your data carefully.
(27 vars, 442 obs)
variable year not found
r(111);
Thanks.
I am trying to clean the data with simple commands.
I could successfully do it one file by one.
My command is below:
//
import delimited "C:\Users\phh84\Google Drive\Data\barley_2016.csv", clear
keep year period state agdistrict county commodity dataitem value
export excel using "C:\Users\phh84\Google Drive\Data\cleaned data\barley_2016.xlsx", sheet("forgams") sheetreplace firstrow(variables)
//
So I'm trying to do all the files in this folder. I tried below command:
//
local files : dir "C:\Users\phh84\Google Drive\Data\cleaned data" files "*.xlsx"
cd "C:\Users\phh84\Google Drive\Data\cleaned data"
foreach file in `files' {
import delimited `file', clear
qui keep year period state agdistrict county commodity dataitem value
qui export excel using 'file', sheet("forgams") sheetreplace firstrow(variables) replace
}
//
I get below error message.
I don't know why I get this error.
Note: 431 binary zeros were ignored in the source file. The first instance occurred on line 1. Binary zeros are not valid in text data.
Inspect your data carefully.
(27 vars, 442 obs)
variable year not found
r(111);
Thanks.
Comment