How can I import and use tags from one Stata file to the current one?

I have a file aa

with a variable x

that is labeled with a value label x_lab

. I would like to use this value label for x

a Stata file variable bb


use bb, clear
label value x x_lab


How do I import a value label x_lab



source to share

2 answers

You can use label save

which stores the value labels in the do-file:

label save x_lab using
use bb, clear


See Stata Help for the label .



This answer method did not work for me as I wanted the label labels created with, for example label var connected "connected household"

, and not the value labels.

I used this advice instead:

sysuse auto, clear 

log using mylog, name(newlog) replace 

foreach var of varlist _all{ 
 di _col(3) "`var'" _col(20) "`:var label `var''" 

log close newlog 

//translate from proprietary format
translate mylog.smcl mylog.txt, replace 
!start mylog.txt 


To fix labels that were expanded across multiple lines, so they just used one, then I replaced \n >

the oversized labels with nothing (in atomic regex mode). I could save TSV there.

In particular:

  • Clear the header and footer text in the output log file.
  • Mac: use "\ n" instead of "\ r \ n".
  • In Windows: first "\ r \ n →" "
  • then leading spaces "\ r \ n" → "\ r \ n"
  • then convert spaces with 3 or more spaces in the middle to tabs "+" → "\ t"
  • (manually edit additional errors in the tab if still left)
  • save as mylog.tsv
  • open in Excel and use the labels table as needed.


All Articles