Announcement

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

  • Conditions on two same value labels with differents names

    Hello,

    I would like to use the value label list exported by "fre" command in a loop to make some conditions. And, i want all values labels (including 0 freq)

    Code:
    sysuse auto, clear
    label define origin 0 "Domestic" 1 "Foreign" 2 "Test", replace
    label define origin2 0 "Domestic" 1 "Foreign", replace
    gen foreign2 = foreign
    label values foreign2 origin2
    fre foreign, includelabeled novalue
    local A "`r(lab_valid)'"
    fre foreign2, includelabeled novalue
    local B "`r(lab_valid)'"
    
    if "`A'"=="`B'" {
        display "oui"
    }
    How can i check in a loop if A and B are the same (or if foreign and foreign2 have same values labels, not only the same value label name).
    With something like that : If A=B then display "Yes"
    With my exemple, A and B are not the same (Domestic, foreign, test vs domestic and foreign) so i don't want to display "Yes". So my loop doesn't work

    Thanks

  • #2
    Try:
    Code:
     
     if `"`A'"'==`"`B'"' {
    (additional ` and ' wrapped around the double quotes)

    Comment


    • #3
      Thanks it works well

      Now i have an other problem, is it possible to drop one value of value label ?
      In my dataset, i have many variables with "I don't know" and "Don't want to answer". I want to replace that by missing value (i did it) but i want to drop the information from value label

      Code:
      sysuse auto, clear
      label define origin 0 "Domestic" 1 "Foreign" 98 "Don't want to answer", replace
      label define origin2 0 "Domestic" 1 "Foreign" 99 "Don't know", replace
      Here, i want one loop to have only 0 and 1 in label values (in my dataset, in all categorical variable, i want to drop 98 and 99 from database and from label values)

      Thanks!

      Comment

      Working...
      X