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
Getting medians for different x variables across yearsHi there Statlist community! I am currently working on summarizing home value appreciation by neigh…
Interpretation of Predict / Margins Results following Nonlinear RegressionsHello everyone, I run xtnbreg for the panel data and would like to use predict/margins following th…
Display date format in regression results when using factor variableHello apologies for the probably trivial question - I am running something like regress y i.month …
difference to difference- dependent variable binaryDear all, I am examining the effect of introduction of minimum wage on employment, my dependent var…
Margins after stcox with multiple records, cluster and time-varied covariatesHi, I have a complex dataset with multiple observations and the Cox model has the cluster option an…
Subscribe to:
Post Comments (Atom)
0 Response to Appending multiple data files that contain string and numeric data types
Post a Comment