Announcement

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

  • Save variable notes as .dta?

    Hi all,

    Is there a way to save variable notes as .dta, along with variable handles? I am working with a survey where the questions are stored as notes not labels, since notes store longer text. I am aware of descsave, where it is possible to save variable labels.

    Thanks,
    Masood

  • #2
    Code:
    // open some example data
    sysuse auto, clear
    
    // add some (silly) notes
    notes make : foo
    notes make : bar
    
    notes mpg : blup
    
    //find maximum number of notes per variable
    local max = 0
    foreach var of varlist * {
        local k = "`:char `var'[note0]'" // stores the number of notes in var `var'
        if "`k'" == "" { // `var'[note0] = "" if no notes specified
            local k = 0
        }
        local max = max(`max', `k')
    }
    if `max' == 0 { // no need to create a file when no notes present
        di as text `"{p}file $S_FN contains no notes{p_end}"'
        exit
    }
    
    // store notes (and variable labels) if there are any
    forvalues i = 1/`max' {
        local charvars `charvars' char`i'
    }
    tempname memhold
    tempfile results
    postfile `memhold' str2045(var varlab `charvars') using `results'
    
    foreach var of varlist * {
        local topost `"("`var'") (`"`: var label `var''"')"'
        forvalues i = 1/`max' {
            local topost `"`topost' (`"`: char `var'[note`i']'"')"'
        }
        post `memhold' `topost'
    }
    postclose `memhold'
    
    use `results', clear // open the dataset we created
    compress // save some memory
    list // display the results
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks Dr. Buis. It works flawlessly for me.

      Comment

      Working...
      X