Alias variables across frames
Did you know you can work with variables in other datasets?
Alias variables behave like a copy of a variable from a linked data frame. Unlike a copy, however, an alias uses very little memory. For example, if the data in our current working frame has variables x1-x3 along with an ID variable, we could use frlink with variable id to link the observations in the current frame with those in frame ydata, which includes the variable id along with variables y1-y3.
. frlink m:1 id, frame(ydata)
Then we use fralias add to create an alias variable for each variable in the linked frame.
. fralias add *, from(ydata)
Now we can use any of the variables in the ydata frame as if they were in our current frame.
. summarize x1 x2 x3 y1 y2 y3 . scatter x2 y2 . regress y3 x1 x2 x3
By using alias variables instead of copying the y1-y3 variables into our current frame, we save memory. And if we want to make changes to the y variables, we need only to make the changes in the ydata frame. The alias variables are automatically updated as well.
For more on frames and their new features in Stata 18, check out our blog post From datasets to framesets and alias variables: Data management advances in Stata.