Epidemiology & Technology

Comparing two Stata Data Sets

Have you ever tried to figure out which variables are common and which are different across two datasets ? Here is the Code to help you out

Do not confuse the ` symbol with the single quote ‘ symbol!

// COMPARE The Two Datasets
quietly des using "Dataset1.dta", varl
local first `r(varlist)' 

quietly des using "Dataset2.dta", varl 
loc second `r(varlist)'

local diff: list second - first
local joint: list second & first

di in red "Different variables:" 
di "`diff'" 

di in red "Common variables:"
di "`joint'"Code language: PHP (php)

Related posts