Announcement

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

  • How to remove the repeated words in variable labels?

    Dear all,
    There are some repeated words in my variable labels, for example, "total revenue_total revenue_total revenue" and "total revenue_sale revenue_sale_revenue".
    I want to remove the repeated words in every variable label. The new label names I want in example are "total revenue" and "total revenue_sale revenue".
    I have no idea at all. Would appreciate any advice! Thanks!

  • #2
    The problem is not sufficiently clear.

    Changing "total revenue_total revenue revenue" to "total revenue" removes all duplicate words (and the underscores). However, "total revenuse_sale revenue" still contains the word "revenue" twice and also preserves an underscore.

    If you can formulate a clear rule, then you can apply that in a loop or use elabel (SSC) to apply the loop for you.

    Perhaps this suffices:

    Code:
    foreach var of varlist _all {
        
        local varlabel : variable label `var'
        
        local varlabel : subinstr local varlabel "_" " " , all
        local varlabel : list uniq varlabel
        
        label variable `var' `"`varlabel'"'
        
    }
    Last edited by daniel klein; 12 Oct 2023, 00:31.

    Comment

    Working...
    X