Hello, I'm quite new to Stata and need help with some code. The idea is that I would like to create a panel data set from an excel workbook that contains numerous sheets (161 sheets). These sheets each contain company data from the Nigerian stock exchange and has identical headings of 19 variables (Date, Price, Market cap...e.t.c). I wish to, therefore, create a panel data set in Stata that combines all these companies.
I have code that creates 161 data files, the problem comes when I wish to append all these data files into one, Stata gives the following error "variable Price is double in master but str17 in using data. You could specify append's force option to ignore this numeric/string mismatch. The using variable would then be treated as if it contained numeric missing value."
I tried force appending but that was not a good idea, I, therefore, request help in modifying my code to convert the variables to numeric before appending.
The excel file is quite large so here is a google drive link in case testing is required. https://drive.google.com/file/d/1JVY...ew?usp=sharing
Your help would be greatly appreciated.
Please find my code below:
clear all
set more off
set excelxlsxlargefile on
*================================================= ========
*import all stocks data from each sheet using a loop
*================================================= ========
forvalues i=1/161 { //put the last number of the last sheet. here there were 3 only
import excel using project_data.xls, firstrow sheet(`i') clear //import each sheet in turn
tempfile john`i' //create a temporary file to save imported from each sheet
save john`i', replace //save the temporary file
}
use "john1" , clear //create a temporary master file from temporary file above
set more off
forvalues i=2/161 { //replace 3 with the highest number in your sheet
append using "john`i'"
}
Related Posts with Appending multiple data files that contain string and numeric data types
Destringing a numerical string*variable with existing mixed valuesI have a variable "height" with all the values being numerical but some values are below 50 were cap…
Generating a variable that tracks the first time 2 IDs appear simultaneouslyHi, I am new to Stata, so I am not very familiar with the codes. I have a dataset with multiple var…
best way to "set obs" when the number of obs is not clearly known?Hi Fellow Listers, I am trying to generate a sequence of values based on a numlist from 1 to X in a…
Variable generationHi Statlist, so, I have a problem constructing two variables. I briefly describe my data here below…
Questions for "drop" participants in long data format for repeated mesurements.Hello! I'd like to ask how to drop observations in such follwing dataset. See the pic below for dat…
Subscribe to:
Post Comments (Atom)
0 Response to Appending multiple data files that contain string and numeric data types
Post a Comment