

Merge m:1 statefips using statepolitical.dta in_class_data.dta is called the "master" file, while statepolitical.dta will be the "using" file. We want to merge the statepolitical dataset to in_class_data, so we want in_class_data to be open while we are merging. Now let's go back to the previous dataset. For countries, there are various codes developed by the World Bank, IMF, etc., and all are preferable to using the names of the country the Stata command kountry works similarly to statastates.
Summarize stata code#
states, look for a FIPS code or postal code rather than the name of the state the Stata command statastates can be used to add them if they are not provided. It's better to use a numeric or alphanumeric code rather than a name to perform a merge. In both datasets, we have variables that describe states.
Summarize stata software#
The first thing to do is identify a variable that appears in both datasets, and that is stored in exactly the same way, which will allow the software to match up information in both datasets. In this example, we have two datasets, in_class_data and statepolitical, and we want to use variables from both in one analysis. Save in_class_data, replace Combining datasets It's a good idea to keep a copy of your original, pristine data, so let's save under a different filename. None of these changes will persist until we save the data. You can also get rid of variables that don't meet certain conditions. If you don't need the variable anymore, you can drop it. Otherwise, it will create missing values. You should also use the ignore() option to skip over any characters that aren't numbers. Replace married = 0 if marst != 3 Using destringĪs in encode, you can (and should) create a new variable using the gen() option. We can easily create a dummy variable for married/not married. With the encode command, add the gen() option to put the newly created numeric values in a new variable.Ĭodebook is very handy for seeing what the actual values of the new variable are. Since the file is in Stata format (.dta) and it is in your working directory (right?), we can open with simply:įirst, use describe to reassure yourself that it is a string. Our sample dataset has an example of each. (This often happens when the values contain dollars signs, commas, etc.) In this case, you should use destring. When the string represents a continuous value, and was just accidentally imported as string.(However, don't encode a string if you plan to use it as a key variable for merging with another dataset see section on merging below.)

When the string represents a categorical (nominal) value, and should be replaced with integers.There are two cases in which you will want to convert string variables to numeric. You can recognize these in the Data Editor because they will be colored red. They take up more memory and are not useful for your regressions, etc. When you want to stop the log, end by closing the log file.Ī major pitfall: string variables. Log using stataworkshop.txt, text replace The log file can be turned on and off, but it is a good idea to help you keep track of what you've done. Log filesĪ log file records the output of the commands as you run your code. It could be /* like this */ for the middle of a line. Stata will ignore the text of the comments when you run your code, but they make your. You can create a new do-file by clicking on the New Do-File Editor button, or typingĪ properly documented do-file will contain comments that communicate your intentions at each step of code. With a correctly written do-file, anyone can reproduce your analysis. Select "Copy Table" from the menu, or "Copy as Picture" for a screenshot-like image, and paste into a Word document.Do-files are scripts for automating Stata commands. Make sure you highlighted the entire table. If you would like to use a data table later, highlight the table and control-click or right-click the table.

(Type summarize dog, detail to get more detailed information about the variable "dog".)įor practice, obtain a detailed summary for the variable "cat". Simply type summarize into the "Command" window. We are going to use the summarize command to get basic information about our data. Notice that the default file format is "Stata Data" Give your datasheet a descriptive title and save it. Before we do anything else, you should save your data. Close the "Data Editor" window, accepting changes when prompted.
