Stata - How to append datasets

  Рет қаралды 11,326

Steffen's Classroom

Steffen's Classroom

Күн бұрын

Welcome to my classroom!
This video is part of my Stata series. A series where I help you learn how to use Stata. In this video, we look at how to append two datasets using the append command in Stata.
Note: What I show here is my take on the topic. I would be happy to receive comments!
Useful links:
►Twitch: / steffens_classroom
►Twitter: / steff5001
►Workpage: www.rug.nl/sta...
►Subscribe: cutt.ly/Qfu9cmV

Пікірлер: 11
@faith...5241
@faith...5241 Жыл бұрын
Thank you!
@juliushinrichsen4961
@juliushinrichsen4961 4 ай бұрын
Thanks! What about appending 2 or more datasets (longitutional data) where all other variables are the same in a questionaire but are spelled sligtly different? e.g. for 2023 = feeling23 and for 2022=feeling22. Is there a quick way to match about 200 variables
@SteffensClassroom
@SteffensClassroom 4 ай бұрын
Hi! If they have a similar stub as for example 'feeling' in your example, then you can do this in a loop. The groups and loops video explains this.
@juliushinrichsen4961
@juliushinrichsen4961 4 ай бұрын
@@SteffensClassroom Hi thanks again for the quick answer. If they are not the same - in my case ch22o_EN_1.0p and ch23p_EN_1.0p would there also be a loop for that?
@SteffensClassroom
@SteffensClassroom 4 ай бұрын
The only time I encountered this, I simply went and changed the name of one of them (:
@boas4530
@boas4530 Жыл бұрын
Thanks! However, all other variables now have the same values in the year after? Was that due to the data sets having the same information or do you need other STATA commands to prevent this from happening?
@SteffensClassroom
@SteffensClassroom Жыл бұрын
This seems to be because of the same information being present. That would be my guess :)
@alyssahgonzalez697
@alyssahgonzalez697 10 ай бұрын
How do we go about it if we want to add in additional years? Do we have to clear the year prior?
@SteffensClassroom
@SteffensClassroom 10 ай бұрын
Hi! The most straightforward would be to add each additional year one by one. It ofc depends on how the data you wish to append looks like. If all the additional data is in one file, you can append everything in one go.
@alyssahgonzalez697
@alyssahgonzalez697 10 ай бұрын
@@SteffensClassroom Great! If I have 10 years worth of data, what would code be after? This is what I have saved from your video and was able to get years 2013 and 2014, curious to know how to follow after with adding 2015,etc. : use "2013 Merged.dta" gen ID = _n gen year = 2013 order ID, first order year, after(ID) save 2013_merged, replace use "2014 Merged.dta" gen ID = _n gen year = 2014 order ID, first order year, after(ID) save 2014_merged, replace use 2013_merged, clear append using 2014_merged sort ID year
@SteffensClassroom
@SteffensClassroom 10 ай бұрын
Ideally you could write a loop to make each year ready for the append, but if you want to do it step by step (not efficient but it works), then all you do is to replace the year with the year you have. After preparing each year, you can then add an append line for each year after: append using 2014_merged So for example, you would add this on the next line: append using 2015_merged A loop version of my code would look something like this: forvalues i = 1(1)2 { sysuse auto`1' gen ID = _n gen year = `i' order year, after(ID) save auto`i'_ready, replace } use auto1_ready, clear forvalues i = 2(1)2 { append using auto`i'_ready save auto_new, replace } In your code, the counter would start at 2013 :) You can also write this as a nested loop to make this more efficient, but this will work.
Using Stata: Merging Data
28:29
Jason Burns
Рет қаралды 3,6 М.
Merging and Appending Files with Stata
26:57
Ali Shuja Classroom
Рет қаралды 3,3 М.
Новый уровень твоей сосиски
00:33
Кушать Хочу
Рет қаралды 4 МЛН
Data management: How to append files into a single dataset
3:41
StataCorp LLC
Рет қаралды 66 М.
Stata - How to merge datasets
12:17
Steffen's Classroom
Рет қаралды 16 М.
Merging Datasets in Stata
19:43
Michelle Benson
Рет қаралды 22 М.
Stata - How to use Do-files
8:57
Steffen's Classroom
Рет қаралды 23 М.
How to Combine Multiple Files in Stata | Stata Tutorial
11:35
The Data Hall
Рет қаралды 14 М.
How to Append (Stack) Data in Stata
12:48
The Data Hall
Рет қаралды 630
Stata - Keep/Drop and Missing values
5:13
Steffen's Classroom
Рет қаралды 28 М.
How to merge data in Stata | Combining datasets in Stata
15:21
The Data Hall
Рет қаралды 19 М.
Merging datasets
5:22
Lauren Hund
Рет қаралды 21 М.
Collapsing Data in Stata
6:12
SebastianWaiEcon
Рет қаралды 39 М.