Announcement

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

  • varlist or in range required

    Dear all,

    Thank you for your help and when programming, I met the following problem.

    local vv "ss*"
    foreach v of varlist `vv'{
    local a: var label `v'
    winsor `v', p(0.01) gen(`v'_x)
    }
    drop `v'
    rename `v'_x `v'
    label var `v' "`a'"

    stata says:
    varlist or in range required
    r(100);

    end of do-file

    r(100);


    what does it mean by "varlist or in range required?"

    Best,

    Eddie


  • #2
    Comments on various levels:

    1. Please use CODE delimiters as requested (FAQ Advice #12)

    Code:
    local vv "ss*"
    foreach v of varlist `vv'{
    local a: var label `v'
    winsor `v', p(0.01) gen(`v'_x)
    }
    drop `v'
    rename `v'_x `v'
    label var `v' "`a'"
    2. Your code can be simplified to remove unnecessary indirection:

    Code:
    foreach v of varlist ss* {
    local a: var label `v'
    winsor `v', p(0.01) gen(`v'_x)
    }
    drop `v'
    rename `v'_x `v'
    label var `v' "`a'"
    3. Your code can be corrected because the loop ends prematurely

    Code:
    foreach v of varlist ss*  {
       local a: var label `v'
       winsor `v', p(0.01) gen(`v'_x)
       drop `v'
       rename `v'_x `v'
       label var `v' "`a'"
    }
    The error message arises because the local macro is not visible outside the loop as you wrote it. Stata sees merely

    Code:
    drop
    which is insufficient as a command. I also added indentation, which makes the code easier for experienced programmers to read.

    4. Personal opinion: overwriting original data with Winsorized versions is bad practice. You can never, ever be 100% certain that the Winsorized version is the only acceptable version.

    Comment


    • #3
      Dear Nick,

      Thank you for your valuable advice and actually I just try to duplicate what others do. It is the author that winsorred the data.

      Best,

      Eddie

      Comment


      • #4
        By the way, winsor is from SSC, as you are asked to explain (FAQ Advice #12).

        I am the author and can add that not allowing a replace option was a deliberate choice.

        In your #3 you seem to be referring to a previous study but "the author" is too vague a reference to allow discussion.
        Last edited by Nick Cox; 03 Jun 2018, 04:38.

        Comment

        Working...
        X