Announcement

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

  • #16
    Hi,

    I seem to be facing a similar problem. I use Stata/SE 12.1 for Windows.
    In my do-file I use 5 .dta files and run the following set of commands on each of them:

    use "$data\phase6_endline_cleaned_WIDE_no_pii.dta" , clear

    gen varname = ""
    gen varlabel = ""
    local i = 1
    set trace on
    foreach v of var * {
    replace varname = "`v'" in `i'
    replace varlabel = "`: var label `v''" in `i'
    local ++i
    }

    This set of commands run for 3 out of four data files. In one of the two that it doesn't run on, I trace to check which variable the code gets stuck on. I browsed to see what this variable contains. It is a byte type variable and contains data.

    These 5 datasets contain 250-380 variables each and no more than 1000 observations in each.

    Could you please help with this error?

    -Pratyusha

    Comment


    • #17
      The code won't work if you have more variables than observations. That's the problem. Suppose you have 250 variables and 220 observations. As soon as you try to put stuff in observation 221 Stata squawks because it doesn't exist.

      Why do you want to do this anyway?

      1. The information on variable names and variable labels is accessible through describe and otherwise.

      2. There is no alignment logically between existing observation contents and what you're putting in observations.

      If you're insistent on doing this you need to increase the dataset size for problematic datasets before the loop with something like

      Code:
      if c(k) > c(N) set obs `c(k)'

      but I have to label that as poor Stata style in my view. Warning: code not tested.

      Comment


      • #18
        Thank you Nick. I understand the logic now.

        The reason I'm doing this is, we've collected data over 6 phases. In some phases new questions were added. I want to save the list of variables from each phase in separate files and then merge to see if there are variables that don't match.

        Comment


        • #19
          I see.

          Alternatively, just append the files and see what leaves blocks of missings.

          With your approach you will have to go back to the data files once you identify the problems. Putting the data together in the first place will give you one dataset to work with.

          There are ways to do what you're doing more directly. Roger Newson has various commands such as dsconcat from SSC/Stata Journal. He is, naturally, the expert on those commands. I don't recollect using dsconcat, but I am totally confident that it's solid code.

          Comment


          • #20
            These are very useful leads! Thank you!

            Comment

            Working...
            X