Example: confidence

Stata: Software for Statistics and Data Science | Stata

Merge datasetsDescriptionQuick startMenuSyntaxOptionsRemarks and examplesReferencesAlso seeDescriptionmergejoins corresponding observations from the dataset currently in memory (called the masterdataset) with those (called the using dataset), matching on one or more perform match merges (one-to-one, one-to-many, many-to-one, and many-to-many), which are often calledjoinsby database also perform sequential merges,which have no equivalent in the relational database for adding new variables from a second dataset to existing observations.

To link datasets in separate frames, you can use the frlink and frget commands. Linking and ... To illustrate the two choices, suppose you have a dataset containing information about individual hospitals, called hospitals.dta. ... within matching values, the first observation in …

Tags:

  Value, Choice, Frame

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Stata: Software for Statistics and Data Science | Stata

1 Merge datasetsDescriptionQuick startMenuSyntaxOptionsRemarks and examplesReferencesAlso seeDescriptionmergejoins corresponding observations from the dataset currently in memory (called the masterdataset) with those (called the using dataset), matching on one or more perform match merges (one-to-one, one-to-many, many-to-one, and many-to-many), which are often calledjoinsby database also perform sequential merges,which have no equivalent in the relational database for adding new variables from a second dataset to existing observations.

2 You usemerge, for instance, when combining hospital patient and discharge datasets. If you wish to add newobservations to existing variables, then see [D]append. You useappend, for instance, when addingcurrent discharges to past link datasets in separate frames, you can use thefrlinkandfrgetcommands. Linking andmerging solve similar problems, and each is better than the other in some ways. You may preferlinking, for instance, when dealing with an individual-level dataset and a county-level dataset. Linkingalso works well when you have nested linkages such as linking a county dataset, a school-within-countydataset, and a student-within-school dataset or when you need to link a dataset to itself.

3 See [D]frlinkfor more information and default,mergecreates a new variable,merge, containing numeric codes concerning the sourceand the contents of each observation in the merged dataset. These codes are explained below in thematch results variables cannot specified without an extension, startOne-to-one merge memory 1:1 v1 using mydata2As above, and also treatv2as a key variable and name the new variable indicating the merge resultfor each observationnewvmerge 1:1 v1 v2 using mydata2, generate(newv)As above, but keep use default merge result variablemergemerge 1:1 v1 v2 using mydata2, keepusing(v3)As above, but keep only observations in both datasetsmerge 1.

4 1 v1 v2 using mydata2, keepusing(v3) keep(match)Same as abovemerge 1:1 v1 v2 using mydata2, keepusing(v3) keep(3)12 merge Merge datasetsAs above, but assert that all observations should match or return an error otherwisemerge 1:1 v1 v2 using mydata2, keepusing(v3) assert(3)Replace missing data values 1:1 v1 v2 using mydata2, updateReplace missing and conflicting data values 1:1 v1 v2 using mydata2, update replaceMany-to-one merge onv1andv2merge m:1 v1 v2 using mydata2 One-to-many merge onv1andv2merge 1:m v1 v2 using mydata2 MenuData>Combine datasets>Merge two datasetsmerge Merge datasets 3 SyntaxOne-to-one merge on specified key variablesmerge 1:1varlistusingfilename[,options]Many-to -one merge on specified key variablesmerge m:1varlistusingfilename[,options]One-to- many merge on specified key variablesmerge 1:mvarlistusingfilename[,options]Many-to -many merge on specified key variablesmerge m:mvarlistusingfilename[,options]One-to- one merge by observationmerge 1.

5 1n usingfilename[,options]optionsDescriptio nOptionskeepusing(varlist)variables to keep from using data; default is allgenerate(newvar)name of new variable to mark merge results; default ismergenogeneratedo not createmergevariablenolabeldo not copy value -label definitions from usingnonotesdo not copy notes from usingupdateupdate missing values of same-named variables in master with valuesfrom usingreplacereplace all values of same-named variables in master with nonmissingvalues from using (requiresupdate)noreportdo not display match result summary tableforceallow string/numeric variable type mismatch without errorResultsassert(results)specify required match resultskeep(results)

6 Specify which match results to keepsorteddo not sort; dataset already sortedsorteddoes not appear in the dialog Options keepusing(varlist)specifies the variables from the using dataset that are kept in the merged default, all variables are kept. For example, if your using dataset contains 2,000 demographiccharacteristics but you want onlysexandage, then typemerge.., keepusing(sex age)..4 merge Merge datasetsgenerate(newvar)specifies that the variable containing match results information should be namednewvarrather thatmergenot be created.

7 This would be useful if you also specifiedkeep(match), becausekeep(match)ensures that all values ofmergewould be that value -label definitions from the using file be ignored. This option should berare, because definitions from the master are already that notes in the using dataset not be added to the merged dataset; see [D] perform an update merge rather than a standard merge. In a standardmerge, the data in the master are the authority and inviolable. For example, if the master andusing datasets both contain a variableage, then matched observations will contain values from themaster dataset, while unmatched observations will contain values from their respective specified, then matched observations will update missing values from the master datasetwith values from the using dataset.

8 Nonmissing values in the master dataset will be specified, then matched observations will contain values from the using dataset,unless the value in the using dataset is eitherupdateorreplaceaffects the meanings of the match codes. SeeTreatment ofoverlapping variablesfor thatmergenot present its summary table of match string/numeric variable type mismatches, resulting in missing values from the usingdataset. If omitted,mergeissues an error; if specified,mergeissues a warning. Results assert(results)specifies the required match results.

9 The possibleresultsareNumericEquivalentcodew ord (results)Description1 masterobservation appeared in master only2 usingobservation appeared in using only3 matchobservation appeared in both4 matchupdateobservation appeared in both, missing values updated5 matchconflictobservation appeared in both, conflicting nonmissingvaluesCodes 4 and 5 can arise only if theupdateoption is specified. If codes of both4 and 5 could pertain to an observation, then 5 is codes and words are equivalent when used in theassert()orkeep() following synonyms are allowed:mastersformaster,usingsforusing, matchesandmatchedformatch,matchupdatesfo rmatchupdate, (match master)specifies that the merged file is required to include only matchedmaster or using observations and unmatched master observations, and may not include unmatchedusing observations.

10 Specifyingassert()results inmergeissuing an error message if there arematch results you did not explicitly Merge datasets 5 The order of the words or codes is not important, so all the followingassert()specificationswould be the same:assert(match master)assert(master matches)assert(1 3)When the match results contain codes other than those allowed, return code 9 is returned, and themerged dataset with the unanticipated results is left in memory to allow you to (results)specifies which observations are to be kept from the merged dataset.


Related search queries