Stata 12 Merging Guide. Nathan Favero Texas A&M University October 19, 2012



Similar documents
Efficient and effective management of big databases in Stata

SPSS for Windows importing and exporting data

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

Importing Xerox LAN Fax Phonebook Data from Microsoft Outlook

enicq 5 External Data Interface User s Guide

Trade Flows and Trade Policy Analysis. October 2013 Dhaka, Bangladesh

VLOOKUP Functions How do I?

Opening a Database in Avery DesignPro 4.0 using ODBC

Using Excel As A Database

Word 2010: Mail Merge to with Attachments

Microsoft Access Rollup Procedure for Microsoft Office Click on Blank Database and name it something appropriate.

Introduction to Microsoft Access 2003

Getting started with the Stata

Create a New Database in Access 2010

Importing from Tab-Delimited Files

2: Entering Data. Open SPSS and follow along as your read this description.

Instructions for creating a data entry form in Microsoft Excel

Search help. More on Office.com: images templates

In This Issue: Excel Sorting with Text and Numbers

Website Development Komodo Editor and HTML Intro

Audacity is a free, totally free, audio editing program. Get it here:

Importing and Exporting With SPSS for Windows 17 TUT 117

SuperOffice AS. CRM Online. Introduction to importing contacts

Inmagic DB/Text for SQL. Importer User s Guide

Import Filter Editor User s Guide

Microsoft Excel 2013: Using a Data Entry Form

NDSR Utilities. Creating Backup Files. Chapter 9

Tommy B. Harrington 104 Azalea Drive Greenville, NC

How to Create a Campaign in AdWords Editor

EXCEL IMPORT user guide

Working with Tables. Creating Tables in PDF Forms IN THIS CHAPTER

Web Intelligence User Guide

Graphing Parabolas With Microsoft Excel

Building Qualtrics Surveys for EFS & ALC Course Evaluations: Step by Step Instructions

Title. Syntax. stata.com. odbc Load, write, or view data from ODBC sources. List ODBC sources to which Stata can connect odbc list

Creating tables in Microsoft Access 2007

File by OCR Manual. Updated December 9, 2008

Adobe Dreamweaver CC 14 Tutorial

Access Queries (Office 2003)

A Quick Guide to Constructing an SPSS Code Book Prepared by Amina Jabbar, Centre for Research on Inner City Health

Appendix III: SPSS Preliminary

To add a data form to excel - you need to have the insert form table active - to make it active and add it to excel do the following:

Step 2: Headings and Subheadings

MAXMAILER USER GUIDE

Microsoft Access Introduction

INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3

Downloading Your Financial Statements to Excel

Guidelines for Completing the VDOT Form C 13CPM

Microsoft Office 2010

Planning and Creating a Custom Database

MicroStrategy Desktop

Microsoft Access 2010 Overview of Basics

Microsoft Access 2010 Part 1: Introduction to Access

Task Force on Technology / EXCEL

DIRECTIONS FOR SETTING UP LABELS FOR MARCO S INSERT STOCK IN WORD PERFECT, MS WORD AND ACCESS

How to Use Swiftpage for Microsoft Outlook

Excel Pivot Tables. Blue Pecan Computer Training Ltd - Onsite Training Provider :: :: info@bluepecan.co.

MICROSOFT ACCESS 2003 TUTORIAL

Using Excel for Analyzing Survey Questionnaires Jennifer Leahy

CRM Global Search: Installation & Configuration

Microsoft Access Basics

Microsoft Access 2007 Introduction

Check out our website!

Reports and Documents Generator for SharePoint ver.: 2.2

ProDoc Tech Tip Creating and Using Supplemental Forms

Microsoft Access 2007 Advanced Queries

Introduction to Microsoft Access 2013

Avery Wizard: Using the wizard with Microsoft Word. This is a simple step-by-step guide showing how to use the Avery wizard in word

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Uploading Ad Cost, Clicks and Impressions to Google Analytics

A. Grouping to Obtain Counts

Excel Database Management Microsoft Excel 2003

Converting Microsoft Access 2002 to Pipe-Delimited ASCII Text Files

Creating a Gradebook in Excel

How to Copy A SQL Database SQL Server Express (Making a History Company)

FrontStream CRM Import Guide Page 2

ANCS+ 8.0 Remote Training: ANCS+ 8.0, Import/Export

Instructions for applying data validation(s) to data fields in Microsoft Excel

MICROSOFT WORD: MAIL MERGE

Home Loan Manager Pro 7.1

Table of Contents. Introduction: 2. Settings: 6. Archive 9. Search Browse Schedule Archiving: 18

Personal Geodatabase 101

How to Create a Spreadsheet With Updating Stock Prices Version 3, February 2015

How to Create and Send a Froogle Data Feed

Title Page. Informed Filler. User s Manual. Shana Corporation Avenue Edmonton, Alberta, Canada T6E 5C5

Tips and Tricks for Printing an Excel Spreadsheet

Introduction to Microsoft Project 2010

Time Clock Import Setup & Use

Excel Templates. & Quote/Invoice Maker for ACT! Another efficient and affordable ACT! Add-On by V

NSSRS Desktop Database Version 11.0 User Guide Version 1.0 July 15, 2015

SES Project v 9.0 SES/CAESAR QUERY TOOL. Running and Editing Queries. PS Query

Merging Labels, Letters, and Envelopes Word 2013

The software shall provide the necessary tools to allow a user to create a Dashboard based on the queries created.

Invoice Quotation and Purchase Orders Maker

Intro to Excel spreadsheets

ProactiveWatch 2.0 Patch Management and Reporting

Transcription:

Nathan Favero Texas A&M University October 19, 2012

Contents Best Practices, pg. 3 Using Merge & Append, pg. 4 Merge, pg. 11 Append, pg. 14 Other Useful Commands, pg. 15 Importing Data into Stata, pg. 20 Delimited Files: Importing Variable Names, pg. 20 Importing from Microsoft Access, Pg. 21

Best Practices Backup everything Save a separate copy of the original files somewhere before you start modifying/merging Always use a do-file to make changes This makes it much, much easier to come back later and fix mistakes or update data Never merge by school/district name (use IDs)

Merge or Append? Merge Adding more variables The same observations can be found in both files. Append Adding more observations (individuals and/or years) The same variables can be found in both files

Merge Adding Variables

Append Adding Observations (Years)

Mixing Merge & Append You can only bind 1 direction (horizontally or vertically) at once. If you re combining both directions, you have to plan the order in which you perform your steps so that you never have to bind in 2 directions at once.

Mixing Merge & Append For example, this won t work.

Mixing Merge & Append This will work.

Mixing Merge & Append Or this will work.

Using Merge merge [n]:[n] [varlist] using [filename] merge 1:1 Try using this if you re unsure. Merging two data files with the same unit of observation Note: If using panel data, varlist must uniquely identify both individual and year merge m:m Rarely used

Using Merge merge [n]:[n] [varlist] using [filename] merge m:1 or 1:m Merging smaller unit of analysis (e.g., school) with larger unit of analysis (e.g., district) Merging panel data (school-year) with cross-sectional (school) or time-series data (year) m corresponds to the more specific data; 1 corresponds to the more general data (if you get this switched, you ll simply get an error) The [varlist] should uniquely identify the more general data (e.g, district, cross-section, or time-series)

Troubleshooting with Merge Does my variable list uniquely identify my observations? (Remember, you must specify both ID and Year variables in 1:1 for panel data.) Have I correctly specified 1:1, 1:m, or m:1? Should I be using append? Do I already have a variable named _merge? Are both files saved as.dta? Are the variable names exactly the same in both files? Are some of my variables strings in one file and numeric in the other?

Using Append append using [filename] append is a much simpler command than merge Just make sure that: The variable names are exactly the same in both files. The variable types (string or numeric) are the same in both files. Both files are saved as Stata files (.dta )

Other Useful Commands destring [varlist], [replace or gen([var name])] ignore([characters to ignore]) Convert a string variable to a numeric variable tab [var name] if regexm([var name], "[^0-9.]") Show all of the values of a variable that are nonnumeric

Other Useful Commands tostring [varlist], [replace or gen([var name])] [force] Convert a numeric variable to a string variable gen [new var name] = string([numeric var name], "%12.0f") Use this command instead of tostring if you have trouble with Stata giving you scientific notation

Other Useful Commands gen [new var name] = substr([string var name],[starting position],[number of characters]) Create a new variable with a fixed number of characters from another string variable (e.g., first 3 characters) order [varlist], after([var name]) order [varlist], first Change the order in which your variables appear

Other Useful Commands duplicates report [varlist] Learn about the number of duplicates duplicates drop Drop any exact duplicates duplicates tag [varlist], gen([var name]) Create a variable that tags duplicate observations

Other Useful Commands foreach var of varlist [varlist] { rename `var' [prefix]_`var' } Adds a prefix to the beginning of each variable name reshape wide [vars that contain varying data], i([identifying var(s)]) j([var that distinguishes observations that have the same identifying var(s)]) Consolidates multiple observations into a single observation by adding variables

Importing Data into Stata: Delimited Files How to get Stata to read in the first row as variable names Logic: At least one of the variables must be a completely numeric variable. 1. Open your file in Excel 2. Create a new column, and give it a variable name in the first cell. (You can put numbers in the column s other cells, or just leave them blank.) 3. Save the file, and reload it into Stata.

Importing Data into Stata: Microsoft Access 2010 External Data Text File (Export)

Importing Data into Stata: Microsoft Access 2010 Select a file location and name. Click OK.

Click Next. Importing Data into Stata: Microsoft Access 2010

Importing Data into Stata: Microsoft Access 2010 Select Include Field Names on First Row. Click Finish.

Click Close. Importing Data into Stata: Microsoft Access 2010

File Export Importing Data into Stata: Microsoft Access 2003

Importing Data into Stata: Choose a location/name. Under Save as type, select Text Files. Click Export All Microsoft Access 2003

Click Next. Importing Data into Stata: Microsoft Access 2003

Importing Data into Stata: Microsoft Access 2003 Select Include Field Names on First Row. Click Finish.