This is old code from a project I worked on a while ago to get portfolio returns and factors from WRDS. The main file to look at here is fffactors.R. The comments there aren't great but it should produce a factor that sorts based on the percentage of foreign income a firm has.

David Kelley, 2018