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
    • 百度学术
    • 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

  • New piece in Guangdong Social Science

    March 29, 2025
  • New article in Explorations in Economic History

    March 21, 2025
  • China Government Employee Dataset-Beiyang (CGED-BY) added to online search

    February 11, 2025
  • Paper in 历史档案 (Historical Archives) by Chen Jun on mid- and low-level Qing military officials

    October 20, 2024
  • Kinship information in the 同年齿录 and related sources completed in August 2024

    August 28, 2024
  • CGED-Q Meeting at Central China Normal University, July 29, 2024-August 2, 2024

    August 6, 2024

Recent Photography

  • HKUST Guangzhou 香港科技大學(廣州)

    March 29, 2025
  • Guozijian and Confucius Temple in Beijing 北京國子監及孔廟

    March 29, 2025
  • Yonghegong in Beijing 北京雍和宮

    March 29, 2025
  • Sunset at Razor Hill, near the HKUST campus 鷓鴣山日落竟

    February 15, 2025
  • Taiwan Province City God Temple 台灣省城隍廟

    February 15, 2025
  • Zhongzheng District in Taipei 臺北中正區

    February 15, 2025
  • A walk from Oban to Dunbeg and back, in the winter

    February 15, 2025

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