stata_cheat_sheets - Data Processing with Stata 14.1 Cheat Sheet For more info see Statas reference manual( Basic Syntax All Stata functions

stata_cheat_sheets - Data Processing with Stata 14.1 Cheat...

This preview shows page 1 - 2 out of 6 pages.

frequently used commands are highlighted in yellow use "yourStataFile.dta" , clear load a dataset from the current directory import delimited "yourFile.csv" , /* */ rowrange( 2:11 ) colrange( 1:8 ) varnames( 2 ) import a .csv file webuse set "" webuse "wb_indicators_long" set web-based directory and load data from the web import excel "yourSpreadsheet.xlsx" , /* */ sheet( "Sheet1" ) cellrange( A2:H11 ) firstrow import an Excel spreadsheet Import Data sysuse auto, clear load system data (Auto data) for many examples, we use the auto dataset. display price[4] display the 4th observation in price; only works on single values levelsof rep78 display the unique values for rep78 Explore Data duplicates report finds all duplicate values in each variable describe make price display variable type, format, and any value/variable labels ds, has(type string) lookfor "in." search for variable types, variable name, or variable label isid mpg check if mpg uniquely identifies the data plot a histogram of the distribution of a variable count if price > 5000 count number of rows (observations) Can be combined with logic VIEW DATA ORGANIZATION inspect mpg show histogram of data, number of missing or zero observations summarize make price mpg print summary statistics (mean, stdev, min, max) for variables codebook make price overview of variable type, stats, number of missing/unique values SEE DATA DISTRIBUTION BROWSE OBSERVATIONS WITHIN THE DATA gsort price mpg gsort price mpg sort in order, first by price then miles per gallon (descending) (ascending) list make price if price > 10000 & ! missing (price) clist ... list the make and price for observations with price > $10,000 (compact form) open the data editor browse Ctrl 8 + or Missing values are treated as the largest positive number. To exclude missing values, use the !missing(varname) syntax histogram mpg , frequency assert price !=. verify truth of claim Summarize Data bysort rep78 : tabulate foreign for each value of rep78, apply the command tabulate foreign collapse (mean) price (max) mpg , by( foreign ) calculate mean price & max mpg by car type (foreign) replaces data tabstat price weight mpg , by( foreign ) stat( mean sd n ) create compact table of summary statistics table foreign , contents( mean price sd price ) f(%9.2fc) row create a flexible table of summary statistics displays stats for all data formats numbers tabulate rep78 , mi gen( repairRecord ) one-way table: number of rows with each value of rep78 create binary variable for every rep78 value in a new variable, repairRecord include missing values tabulate rep78 foreign , mi two-way table: cross-tabulate number of observations for each combination of rep78 and foreign Create New Variables see help egen for more options egen meanPrice = mean( price ), by( foreign ) calculate mean price for each group in foreign pctile mpgQuartile = mpg , nq = 4 create quartiles of the mpg data generate totRows = _N bysort rep78 : gen repairTot = _N _N creates a running count of the total observations per group bysort rep78 : gen repairIdx = _n generate id = _n _n
Image of page 1

Subscribe to view the full document.

Image of page 2

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes