Тёмный

Stata - How to append datasets 

Steffen's Classroom
Подписаться 6 тыс.
Просмотров 12 тыс.
50% 1

Опубликовано:

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 11   
@faith...5241
@faith...5241 Год назад
Thank you!
@juliushinrichsen4961
@juliushinrichsen4961 5 месяцев назад
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 5 месяцев назад
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 5 месяцев назад
@@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 5 месяцев назад
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 11 месяцев назад
How do we go about it if we want to add in additional years? Do we have to clear the year prior?
@SteffensClassroom
@SteffensClassroom 11 месяцев назад
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 11 месяцев назад
@@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 11 месяцев назад
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
Просмотров 3,9 тыс.
Stata - How to merge datasets
12:17
Просмотров 16 тыс.
Combining data files in Stata
7:53
Просмотров 47 тыс.
Merging and Appending Files with Stata
26:57
Просмотров 3,4 тыс.
Stata - How to use gen(erate) & egen
6:17
Просмотров 14 тыс.
Introducing Python in Excel
19:01
Просмотров 1,6 млн
How to Append (Stack) Data in Stata
12:48
Просмотров 690
Merging Datasets in Stata
19:43
Просмотров 22 тыс.
Stata - Keep/Drop and Missing values
5:13
Просмотров 28 тыс.