Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transfer variable labels from excel list into stata dataset

    Dear colleagues.

    For various data-release/red-tape reasons, I have been given a Stata dataset (wide format) with the variable labels included in a separate variable list in excel (e.g. segment of excel table below).

    Does anyone know an efficient way or coding to link/transfer these label 'Descriptions' from the below excel sheet into the Stata dataset (according to the variable names) - without having to go through and label each one individually. The VariableID below is equivalently named in the Stata dataset (but the variables just don't have the labels or 'description' in the Stata dataset).

    Many thanks in advance,
    Patrick
    VariableID Description
    1 RI_REC_ID Release ID
    2 HIP3_4HC Measured hip circumference: Mean of three measurements in cms (4HC)
    3 HIP2_4HC Measured hip circumference in cms (4HC)
    4 HIP1_4HC Measured hip circumference in cms (4HC)
    5 HC3DATE_DECDAYS* Date of third health check (3HC) (as decimal)
    6 HLTHCHK3 Participant attended 3HC? 1=yes, 2=no(3HC)
    Attached Files

  • #2
    I've got some labels in excel for some sets as well, and use below formula. That's in excel. Then copy all lines and copy paste into the command window or your do file
    Code:
    *Note NOT Stata code
    =CONCATENATE("label var ",A2," ",CHAR(34),B2,CHAR(34))
    I'm sure some Stata purist will come along and tell you to import your xls file with your labels into Stata and then apply some Stata code, but this works.
    Click image for larger version

Name:	Untitled2.png
Views:	1
Size:	15.7 KB
ID:	1504763

    Last edited by Jorrit Gosens; 25 Jun 2019, 05:17.

    Comment


    • #3
      Jorrit Gosens - many thanks! Great trick!

      Comment

      Working...
      X