solohost.blogg.se

Stata datasets
Stata datasets







stata datasets

This example uses the auto dataset (you can load it using line 1 from below). Take a moment to familiarize yourself with the dataset before proceeding. You could use postfile to write a file containing this paired down data set. Suppose you had a dataset in which you wanted only a specific set of observations and two of the variables. The easiest way to create a subset of your data is to use a loop. The colors indicate this correspondence between line 2 and line 4. You will have to loop or repeat this command for every observation you want to write.Įxample 1: Using Postfile to create subsets of data

stata datasets

A variable can have one or several values (information for one or several cases). A dataset is a collection of several pieces of information called variables (usually arranged by columns). Data written in each variable is enclosed in parenthesis and corresponds to the order specified in line 2. What is Stata It is a multipurpose statistical package to help you explore, summarize and analyze datasets. Line 4 will write one observation to your dataset. You have to specify the tempname (`memhold') again. This can be useful but be careful - you may overwrite something you want!

#Stata datasets trial#

That is because I tend to have to rerun postfile scripts frequently as they tend to be written through trial and error. Notice that I have used the replace option. This can be confusing because string variables are then two words and numerical words just one. Additionally, you have to specify string variables with a str followed by the number of characters desired. The order you specify them in will be the their order in your new data set. Here, I've specified the tempname (`memhold') followed by the variables I'm going to save. Line 2 sets the names of the variables that will be in your new dataset. Each postfile related command that follows will reference this tempname (`memhold'). Line 1 creates a temporary object (aka "tempname") to save the contents of the file you are creating temporarily. The above 'snippet' needs to be changed to fit your needs everytime you want to use it, but because its quite a bit to memorize its better to save this text somewhere to call upon it when needed.

stata datasets

Post `memhold' (your_str_var) (your_num_var) Postfile `memhold' str10 stringvar numvar using "C:/Filename.dta", replace









Stata datasets