

They go after any variable list or if condition, following a comma. Explain why you handled missing values the way you did in both cases. Include the variables used in the conditions so you can spot-check your results. Then browse foreign cars that cost less than $5,000 and are not known to have poor repair records ( rep78 less than or equal to 3). ensures you're excluding all missing values.Įxercise: Browse domestic cars that get more than 25 miles per gallon and are known to have good repair records ( rep78 greater than 3). excludes them because extended missing values are greater than the generic missing value. But if the data set included extended missing values, the condition !=. ? In this data set it makes no difference. So add a second condition to exclude them: Other operators you can use are: =Īn easy shortcut is to think of missing values as (positive) infinity, and since infinity is greater than 3 cars with a missing value for rep78 are included in the list. Note the two equals signs! In Stata you use one equals sign when you're setting something equal to something else (see Creating and Changing Variables) and two equals signs when you're asking if two things are equal. An if condition comes after a variable list: This allows you to do things with subsets of the data. It will only act on those observations where the condition is true. If ConditionsĪn if condition tell a command which observations it should act on. There are shortcuts for creating long lists of variables without typing them all, or variable lists containing variables that match a pattern, but we'll discuss them in Data Wrangling in Stata.Įxercise: browse the make and weight of each car. Listing one or more variables after a command tells the command it should only act on the variables listed: The key to using the data browser effectively is being able to view the parts of the data set you care about, and the next two syntax elements will help us do that. Looking at your data is a great way to get a basic understanding of it, but even with this small data set you can't see all of it. Browse mode won't let you accidentally change your data. The browse command opens the Data Editor in browse mode, which is what you should always use unless you're doing data entry. We'll explore the elements of Stata syntax using a command that makes it easy to see what they do: Commands that can destroy data, like replace, cannot be abbreviated. Many commands can be abbreviated: sum instead of summarize, tab instead of tabulate, reg instead of regress. Normally the command itself comes first and then you tell Stata the details of what you want it to do after. They tell Stata to do something: summarize, tabulate, regress, etc. This syntax allows you to control what part of the data set the command acts on, modify what the command does, and more. If you haven't already, load the automobile data set that comes with Stata by running:Īlmost all Stata commands use a standard syntax.


Skip to the content that follows this video If you're new to Stata we highly recommend starting from the beginning. This is part three of Introduction to Stata.
