

#Or in stata manual
View the entire collection of UVA Library StatLab articles.1 Erik Biørn, Department of Economics,University of Oslo, JanuECON 5103 ADVANCED ECONOMETRICS PANEL DATA, SPRING 2010 A TUTORIAL FOR PANEL DATA ANALYSIS WITH STATA This small tutorial contains extracts from the help files/ Stata manual which is available from the web. Just pick the right one depending on the datasets you’re are going to combine, and what kind of end product you would like to obtain from the merging. So the steps are really the same for one-to-one and one-to-many merge. | 2 Lannister Tywin 1 Tyrion 1 matched (3) | | 2 Lannister Tywin 1 Tyrion 1 matched (3) |ģ. | 2 Lannister Tywin 1 Cersei 1 matched (3) |Ĥ. | 1 Baratheon Robert 0 Joffrey 0 matched (3) |Ģ. | familyid family dname dstatus kname kstatus _merge |ġ. * use the dads file as master file and kids file as using file If you get more records in a dataset, which we normally do, you can summarize this _merge variable to see if you have any mismatched case. In this example, we can easily inspect every observation to see if they are matched. The value of _merge is 1 if the observation comes form file1 (master file) only, 2 if the observation comes from file2 (using file) only, 3 if the observation comes from both of the two files – in other words, 3 means the observation is matched. Note Stata creates a _merge variable in the merged results, which indicates how the merge was done for each observation. | 6 Tyrion Lannister 36 2 1 matched (3) | | 5 Robert Baratheon 7 2 0 matched (3) |Ħ.

| 2 Cersei Lannister 36 1 1 matched (3) |ĥ. | id name family epi season status _merge |Ģ. * merge the two files, we base this merge on the id variable in both files * First, we create the new data file with id and the new variable status In this case, if we want to combine this new data file to got3, we should use one-to-one merge to match the records in the two files. Say we have another data file contains the id variable and the same 6 observations, but with a new variable called status – in other words, a new column. In the dataset we just appended (got3), we have 5 variables, with the id variable uniquely identifying the 6 observations in the data. Below we use two examples to demonstrate one-to-one merge and one-to-many merge.

It is usually pretty straightforward to append data, however it sometimes gets a bit tricky when you need to combine data in a column-wise manner, that is, merge data. Now we have a combined dataset with a variable indicating which original dataset the observations come from – although this dataset is officially fictional, as Robert Baratheon was not seen in season two… Merge data: -merge.

We can simply do this by generating a variable indicating season before we append them. In some cases this may cause some inconvenience in tracing back to the original files or even problems in data analysis – say, in this case, if got1 and got2 contain records from two different seasons, we should mark that in the combined dataset. The combined dataset looks right to me, however we are not able to tell which dataset the observations come from. * combine the two datasets and see the results
