Cameron D. Campbell 康文林

Family, Social Mobility, and Inequality in China and in Comparative Perspective

Menu
  • Research
    • Abridged CV
    • Full CV (PDF)
    • 2 page CV (PDF)
    • Google Scholar
    • CNKI
    • 百度学术
    • ORCID
    • HKUST Repository
  • News
  • Data
    • China Government Employee Database – Qing (CGED-Q) 中国历史官员量化数据库(清代)
      • Download Data
      • Search by Name
      • CGED-Q Jinshenlu Public Release – Resources for Users
    • China Multigenerational Panel Databases 中國多代人口数据庫
      • Download Data
  • Lee-Campbell Group
    • People
    • Projects
    • Publications
  • Photography
    • Photo site 摄影网站
    • Map view
    • Updates
  • Contact
Menu

Opening old Excel files in STATA 12

Posted on May 11, 2013 by camecamp

I ran into some importing old Excel files into STATA 12.  Since I thought others would probably be encountering the same problem, I decided to write a blog post about it.

We’re getting ready to produce a draft release of our China Multigenerational Panel Dataset – Shuangcheng (CMGPD-SC) so that users can kick the tires and report problems before we submit a final version to ICPSR for dissemination there.

As part of the preparation, we wanted to take advantage of the new facility in Stata 12 that allows Excel files to be opened directly.  Our ‘raw’ data consist of Excel spreadsheets entered by our coders, one per register.  Registers are annual or triennial.  For our Liaoning dataset, we have 737 registers coded.  For Shuangcheng, we have 338.  Previously, our procedures for automating the import of the registers in Stata were clumsy, and rarely survived upgrades to Stata or Windows.  At one point we were using the odbc command to loop through and read all the registers, but that broke when we moved to computers that were running 64 bit windows.  Then we wrote a macro to loop through the Excel files and write them to tab-delimited text fields, which STATA could read.

Converting our programs to use import excel was fairly straightforward.  Basically it just mean substituting import excel for insheet.

When we began running the programs, however, STATA was reporting that it could not load files, and came back with an r(603).  I did notice it could open all .xlsx files, but had more trouble with .xls files.  I began to wonder if the problem was with older versions of Excel files.  Perhaps the import capability assumed a recent version of Excel.  I saved some of the files as .xlsx files and sure enough, STATA could read them.

At that  point, it became necessary to convert the thousand or so files that were in older versions of Excel to .xlsx files.  Opening them one by one and saving them to .xlsx would be impractical.

I poked around on the net, and found that Microsoft had an Office File Converter tool available for download.   Here is an introduction and here is the download.  The tool requires that the Microsoft Office Compatibility Pack be installed.  By modifying the ofc.ini file, and adding the name of a folder under [FoldersToConvert] it is possible to direct OFC to attempt to convert all the old .xls files it finds in a specified folder to .xlsx.

[FoldersToConvert]
fldr=C:UsersCameronDropboxSharedSkydriveCMGPD DataLN

Here is what my [ConversionInfo] section ended up looking like:

SourcePathTemplate=********
DestinationPathTemplate=*1*2*3*4*5*6*7*8Converted

I ran ofc and sure enough, it chugged through the files and converted them and placed them in a directory under the original folder that was called Converted.

Now Stata is happily chewing through the converted files.

 

 

 

  • Instagram
  • Photography website
  • Bluesky
  • LinkedIn

Recent Posts

  • Working paper on kin networks of local officials in the late Qing

    January 22, 2026
  • New edited volume Quantitative History of China: State Capacity, Institutions, and Development

    November 12, 2025
  • Chinese translation of our original record linkage paper

    November 5, 2025
  • New manuscript about Kin Networks of Exam Degree Holders

    November 4, 2025
  • Improved pipeline for nominative linkage of historical records written with Chinese characters

    October 1, 2025
  • Special issue “Inequality, economic stress, and demographic response” in Explorations in Economic History

    August 14, 2025

Recent Photography

  • Dihua Street in Taipei, at night 臺北迪化街夜景

    February 28, 2026
  • Taiping Elementary School at night, Keelung

    February 28, 2026
  • Downtown Keelung seen from Huzishan, at night

    February 28, 2026
  • Zhongshan No. 1 Road, Alley 113, Keelung, Taiwan at Night 台灣中山一路113巷夜景

    February 28, 2026
  • Keelung Downtown at night 基隆市中心的夜景

    February 28, 2026
  • Chongqing by Day

    February 20, 2026
  • Chongqing waterfront promenade, near Chaotianmen

    February 20, 2026

©2026 Cameron D. Campbell 康文林 | Theme by SuperbThemes