![reshape stata reshape stata](https://www.stata-uk.com/media/wysiwyg/software/stata/data-editor-paste-special.png)
The variables you list are level one variables any variables you do not list are assumed to be level two variables. The reshape command always reshapes the entire data set, but to do so it needs to understand which variables are level one and which are level two. This is a bit different from the usual syntax where the list of variables tells the command which variables to act on. Then you give a list of all the level one variables. The syntax of the reshape command begins by specifying the form you want, in this case wide. Reshape wide age race maritalStatus edu income female hispanic, /// In wide form it would have one observation per household, and reshape can do that for you: The data set has one observation per person, or level one unit, so the data set is currently in long form. The variable householdIncome is a level two, or household-level variable, because any persons who live in the same household will have the same value of householdIncome. At this point we don't have any variables that describe the household, so let's make one before proceeding:īy household: egen householdIncome = total(income)
![reshape stata reshape stata](https://sscc.wisc.edu/sscc/pubs/mi/conv2.png)
The variables age, race, maritalStatus, edu, income, female, and hispanic all describe individual persons, making them level one variables. The level one and level two identifier variables are person and household, and you can confirm that they uniquely identify observations with: Recall that this is hierarchical data consisting of people living in households, so a person is a level one unit and a household is a level two unit. Start a do file that loads the cleaned version of the 2000 American Community Survey we worked with earlier: In particular, you need to know the level one and level two identifiers, and which variables are level one variables and which are level two. The reshape command is very simple to use, if you understand the structure of the your data set.
#Reshape stata how to
We'll also learn how to turn a data set containing both level one and level two units into a data set containing just level two units. We'll learn how reshape data so we can switch at will between the long form (one row per level one unit) and wide form (one row per level two unit). In this section we'll learn how to restructure data sets. (you can have more than one).This is part six of Data Wrangling in Stata. I(ID) tells Stata that ID is the identifier The text WEIGHTĬALORIES indicates the variables to be converted, and Restructure data from wide format to long format wide In the above code, long tells Stata that you want to To convert data from the long to the wide format, enter: reshape wide WEIGHT CALORIES, i(ID) j(TIME) To convert data from the wide to the long format, enter: reshape long WEIGHT CALORIES, i(ID) j(TIME) The wide format uses one row for each observation or participant: ID weight1 weight2 weight3 calories1 calories2 calories3 The long format uses multiple rows for each observation or participant: ID WEIGHT CALORIES TIME
![reshape stata reshape stata](https://crackkits.com/wp-content/uploads/2021/02/Stata-Crac.jpg)
Two outcome variables (weight and calories), under three different The following example data contains two participants measured on
![reshape stata reshape stata](https://cscar.github.io/workshop-stata-intro/images/wide-vs-long.png)
Stata reshape command can convert the data files between Information here may no longer be accurate, and links may no longer be available or reliable.įollowing are two different ways to set up repeated measures data. This content has been archived, and is no longer maintained by Indiana University.