Announcement

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

  • Rename value labels: elabel getting stuck - Stata 17

    Hi,

    I want to merge two data sets (household-level data and individual-level data) and some of the value labels are not unique between the two datasets (e.g., label labels1 already defined). If not modified, they get overwritten when merging.

    I tried to use the community-contributed command elabel before merging to rename the labels, but the command does not complete execution. It gets stuck and nothing happens even after a long wait (because the data set is relatively large, I also tried keeping only two variables and value labels, but had no luck).

    My version of elabel, downloaded from github is:
    *! version 4.4.2 28dec2021 daniel klein

    ***Individual-level data
    use person, clear

    ***elabel command
    elabel rename (*) (*_person)

    ***merging person and hh data sets (if this step is done without modifying the labels, the labels get overwritten and some household variables get value labels from the individual-level data)
    merge m:1 serial using hh

    Anyone knows why elabel might not be working, or have suggestions for me to try?
    I did install a previous version of elabel from ssc, and then uninstalled it and installed the one from GitHub after reading this post.

    As a workaround, this code worked in this case (where the labels are named from 0 to 780)
    forval i = 0/780 {
    label copy labels`i' labels`i'_person
    findname, vallabelname(labels`i') local(myvars)
    foreach var of local myvars {
    label values `var' labels`i'_person
    }
    label drop labels`i'
    }

    Thanks for any leads!

  • #2
    Can you post a reproducible example? I cannot replicate the problem:

    Code:
    // toy dataset
    clear all
    
    // define 781 value labels
    forvalues i = 0/780 {
        // ... with 300 entries, each
        forvalues j = 1/300 {
            label define labels`i' `j' "foo" , add
        }
    }
    
    // set 100,000 observations (I do not think it matters)
    set obs 100000
    // and create, say, 3,000 variables
    forvalues i = 1/3000 {
        // ... to which we attach one of the labels randomly
        local l = runiformint(0, 780)
        generate var`i':labels`l' = runiform()
    }
    
    // now change the value label names with -elabel- (GitHub)
    
    timer clear
    timer on 1
    elabel rename (*) (*_person)
    timer off 1
    
    timer list
    produces

    Code:
    . elabel rename (*) (*_person)
    
    . timer off 1
    
    .
    . timer list
       1:      0.88 /        1 =       0.8830
    
    .
    end of do-file
    meaning it takes less than a second.
    Last edited by daniel klein; 21 Mar 2023, 02:26.

    Comment

    Working...
    X