Announcement

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

  • store -note- in a local macro?

    This should perhaps be obvious, but my searches are turning up too many unrelated items.

    I used Stat/Transfer to convert a number of SPSS files to Stata files. I suppose because the variable names all have a long (and unnecessary) stem, they are stored as -note-s in the Stata dataset. I would like to loop over the variables, retrieve the -note- attached to each one, remove the stem, and then label the variable. Something like:

    Code:
    foreach Q in varlist q_* {
         local name : note `Q' 1
         local name = subinstr("`name'","`stem'","",1)
         label var `Q' "`name'"
    }
    if such an extended macro function -note <varname> <note #> - existed. Given that it doesn't, is there a work around for capturing the note? I suppose I could log all variable notes, process it separately to produce a table of variable labels, then use that to relabel the variable list, but there should be an easier way. Is there?

    J



  • #2
    The secret is that notes are really characteristics. There is example code in findname (SJ) for various retrievals.

    Comment


    • #3
      Aha.


      thanks much,
      J

      Comment


      • #4
        Also note that you can reference a characteristic directly, as if it is a local macro name:

        Code:
        sysuse auto, clear
        note make: The make of the car
        note price: The price of the car
        note mpg: The mpg of the car
        
        char list
        
        * show how to reference a note directly
        dis "`make[note1]'"
        
        * loop to label vars
        foreach v of varlist make-mpg {
            label var `v' "``v'[note1]''"
        }
        
        des make-mpg

        Comment

        Working...
        X