Announcement

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

  • How to write/ display label text instead of number

    Hi all,

    I want to write some text to a text file that contains the label text, but I keep getting a numeric value back. Grateful to anyone who could help or provide some insights.

    A simplified version is:
    Code:
    use my_data
    generate id = _n
    
    * label attributes and levels
    label define WFHlab 1"Allowed" 2 "Not allowed"
    label values WFH WFHlab
    
    foreach obs of numlist 1/`=_N' {
        quietly summarize id if id == `obs'
        local WFH_lab = WFH[r(min)]
        display `WFH_lab'
    }
    I get the level digit back instead of the label text

    Thank you


  • #2
    Code:
            
     use my_data
    generate id = _n  
    * label attributes and levels
    label define WFHlab 1"Allowed" 2 "Not allowed"
    label values WFH WFHlab  
    foreach obs of numlist 1/`=_N' {    
          quietly summarize id if id == `obs'    
         local WFH_lab = WFH[r(min)]    
         local f0: label WFHlab `WFHlab'    
         di "`f0'"
    }
    Last edited by alejoforero; 13 Mar 2023, 14:05.

    Comment


    • #3
      Code:
      display `"`:label (WFH) `WFH_lab''"'
      will display the label assigned to the value of `WFH_lab' in variable WFH.

      But you code doesn't make sense to me. -summ id if id == `obs' will necessarily return the value `obs' for the mean, min, and max, 0 for the standard deviation, and some informative value for N. So your second command in the loop is really just assigning the value `obs' to WFH_lab. Did you perhaps mean -summ WFH if id == `obs'- or something like that?

      Comment

      Working...
      X