How to Upload a Data File on Stata
Bring ASCII Data into Stata
Please note the assumptions that went into the creation of this certificate: it is assumed the user has access to Stata software and has some bones Stata experience. Also, please note that this process is based on Roper Center datasets only and we recommend the use of the Stata "do file" for the all-time results.
The Best Way to Approach This Task
- Review the study documentation (as well referred to as the codebook) offset to identify the questions you want to clarify in Stata. The codebook fully describes the dataset. Information technology includes information regarding the survey such equally the study number, championship, name of the survey organization that conducted the report, the sponsor (if applicable), the field dates, type of sample(s), sample size, type of interview, weight information, and number of records per respondent. The study methodology and any usage notes may likewise announced. The codebook/questionnaire includes the question numbers, question text, responses including the codes and labels, as well every bit the card and column locations for each variable. Some studies may include a listing of variables and the card and column location for each variable. The back of the codebook includes a dump of the information referred to as an ten-ray which shows the un-weighted number of cases in each dial for each column.
- Download both the documentation and data file at the same fourth dimension
- Based on the number of records per respondent listed on the codebook cover folio, determine the appropriate Stata "exercise file" needed (unmarried record or multi-tape)
- Utilise the examples and rules provided to create the required Stata "do file."
- Weighting – If the codebook indicates there is a weight variable, the analysis should be run weighted in order to make the responses exist representative of the population surveyed, and to replicate the responses published by the survey organisation.
We will focus on determining the appropriate Stata "practice file" needed and creating the required Stata "do file."
ASCII Data Files
ASCII data files are often referred to every bit "text" files or "patently text" files. They contain no formatting information–just rows of characters. The "mapping" data for the characters comes from the codebook discussed in step ane in a higher place.
Two types
- Single Record – respondent's output is recorded on one line or row
- Multi-Record – respondent'southward output is recorded on more than than ane line or row
Is the ASCII Single Tape or Multi-Record?
Refer to the codebook encompass folio where the number of records per respondent is listed. If this number is "1" the file is a single tape file, otherwise it is a multi-record file.
Bringing ASCII Data into Stata
Stata "do file"
Since no structure is included in an ASCII data file, a Stata "do file" must be created to instruct the software on where to go to get particular variables (questions).
Stata Commands That Every Stata "do file" Should Have
- Articulate – This ensures Stata'due south retentiveness is clear
- Fix more off – This control makes sure Stata runs all commands in the "exercise file" without stopping
- Infix – A command that tells Stata to read a stock-still-format ASCII data file
- Variable names – Assigns a name to each variable and includes information on the column location of the variable in the raw text (ASCII) file
- Using– A suffix that tells Stata the path directory of where the raw information (ASCII) file is located
- Variable Labels – Assigns descriptive labels to variables in the dataset
- Value Labels – Assigns response labels for each variable.
Case of a Unmarried Record Stata "do file" |
---|
*this program reads a single record data file into Stata clear infix Q08 50-51 Sex 98-99 using "c:\temp\abcw887.dat" label var Q08 "FBI Monitoring" characterization define Q08l i "Back up" ii "Oppose" 8 "DK" 9 "NA-Refused" |
Stata Syntax Rules
-
Command syntax in Stata is example sensitive
- Comments should start with an asterisk (*)
- The Stata "do file"extension is .practise
- Stata programs can be written upwards and edited in a basic text file editor (Notepad or Wordpad)
Run the "do file"
There are two means to run a "do file." One is to open the file in Stata's "do file" editor, highlight all commands and click "do." This is helpful for making sure at that place are no errors in the "do file." The near straightforward mode, once you have a "do file" gratis of errors, is to open Stata and select, from the pull down menu, the run button on Stata. Do then click the name of your "do file" to run it. This will run the commands in your "do file" and read your dataset into Stata.
Example of Multi-Record Stata "practice file" |
---|
*this program reads a multi-record data file into Stata articulate nfix 4 lines 1: str Q01a 6 str Q01b vii 2: Q22 viii-ix 3: Sex 28 iv: PartyId 57 |
Tips & Troubleshooting
- If you make a fault in your "do file", Stata will execute every command up until the mistake and produce an mistake message indicating which command has the error.
- If this is your first attempt at writing a Stata "do file", run the file after one-two questions to make error identification easier. Once the file is error-gratuitous you can add additional questions and run the file again, standing the process until all questions have been included.
- The general principles outlined hither for Stata apply to SAS and SPSS every bit well. The syntax will be dissimilar, but the principles are the aforementioned.
- Sometimes you may run out of memory in using a large datafile. Add the command "set mem 1000m" to allow Stata to use 1 gigabyte of memory (this depends on how much memory your system has).
Complete Stata "exercise files" with ASCII Data File and Codebook
- Unmarried Record Stata "exercise file" and Dataset Abstract
- ABC News/Washington Postal service Poll # 1991-9142: Thomas Vote Delay Poll #ane, October eight, 1991
- Study # USABCWASH1991-9142
- Multi-Record Stata "practise file" and Dataset Abstract
- Gallup/CNN/USA Today Poll # 1998-9808026: Anti-Terrorist Air Strikes, Baronial 20, 1998
- Study # USAIPOCNUS1998-9808026
Additional Stata Resources
Research Technologies at Indiana Academy (https://kb.iu.edu/d/aflyl)
UCLA Academic Engineering science Services (https://stats.idre.ucla.edu/stata/)
This Page Powered past Stata: Software for Statistics and Science
Source: http://ropercenter.cornell.edu/bring-ascii-data-stata
Postar um comentário for "How to Upload a Data File on Stata"