Announcement

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

  • Loop not work

    I am currently involved in working with data from the Multiple Indicator Cluster Surveys, specifically the Household survey wave 6. My primary task involves calculating the learning outcomes of children aged 5 to 17 years. To assess reading skills, we utilize a variable called "read correctly," which takes values from 1 to 72 words. These values correspond to whether a child read a particular word correctly, incorrectly, or did not reach the word.
    My objective is to determine the total number of words (out of 72) that a child correctly read. To achieve this, I have implemented specific loops within the survey data. Specifically, I examine the variable FL28, which indicates whether interviews have been completed or not. Additionally, I use variables FL19w1 …… to FL19w72 to assess each word's reading accuracy. FL19w1 indicates the status of word 1, FL19w2 corresponds to word 2, and so forth, up to word 72.
    By analyzing these variables and employing appropriate loops, I can calculate the total number of words that each child read correctly. This process helps us better understand the children's reading proficiency within the surveyed population. But result show mismatch as show in image.

    foreach var in target read_corr alit alnfe readskill target_num number_read number_dis number_add number_patt numbskill {
    gen `var'=0 if FL28==1
    }
    /* 4a. For read_corr: First derive the 90% reading target. To do this, replace the values for target based on FL19W */
    foreach num of numlist 1/72 {
    replace target=target+1 if FL19W`num'==" "
    }







    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int HH1 byte(HH2 LN FL28 FL19W2 FL19W71 FL19W72) float(target read_corr alit alnfe readskill target_num number_read number_dis number_add number_patt numbskill)
    1  1  3 . . . . . . . . . . . . . . .
    1  4  3 . . . . . . . . . . . . . . .
    1  5  5 . . . . . . . . . . . . . . .
    1  6  4 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    1  8  3 . . . . . . . . . . . . . . .
    1  9  3 . . . . . . . . . . . . . . .
    1 10  4 . . . . . . . . . . . . . . .
    1 11  6 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    1 12  3 . . . . . . . . . . . . . . .
    1 13  5 1 1 2 2 0 0 0 0 0 0 0 0 0 0 0
    1 14  4 . . . . . . . . . . . . . . .
    1 16  9 . . . . . . . . . . . . . . .
    1 18  9 3 . . . . . . . . . . . . . .
    1 19  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    1 20  4 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2  1  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2  2  5 . . . . . . . . . . . . . . .
    2  3 15 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2  4  9 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2  5  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2  6  4 . . . . . . . . . . . . . . .
    2  7  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2  8  3 . . . . . . . . . . . . . . .
    2  9 10 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2 10  8 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2 11  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2 12  3 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    2 13  5 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2 14  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2 15  3 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    2 16  5 . . . . . . . . . . . . . . .
    2 17  2 3 . . . . . . . . . . . . . .
    2 18  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    2 19  7 . . . . . . . . . . . . . . .
    2 20  2 . . . . . . . . . . . . . . .
    3  1  5 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    3  2  5 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    3  3  4 5 . . . . . . . . . . . . . .
    3  4  5 . . . . . . . . . . . . . . .
    3  5  5 . . . . . . . . . . . . . . .
    3  6  6 . . . . . . . . . . . . . . .
    3  7  5 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    3  8  6 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    3 10 14 . . . . . . . . . . . . . . .
    3 11  5 . . . . . . . . . . . . . . .
    3 13  4 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    3 14  8 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    3 15  3 3 . . . . . . . . . . . . . .
    3 16  6 . . . . . . . . . . . . . . .
    3 17  3 . . . . . . . . . . . . . . .
    3 19  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    3 20  5 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    4  2  3 3 . . . . . . . . . . . . . .
    4  3  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    4  4 13 . . . . . . . . . . . . . . .
    4  5  5 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    4  6  7 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    4  7  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    4  8  6 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    4  9  4 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    4 10  5 3 . . . . . . . . . . . . . .
    4 11  5 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    4 12  6 . . . . . . . . . . . . . . .
    4 13  4 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    4 14  8 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    4 15  6 2 . . . . . . . . . . . . . .
    4 16  6 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    4 17  3 . . . . . . . . . . . . . . .
    4 18  8 . . . . . . . . . . . . . . .
    4 19  3 . . . . . . . . . . . . . . .
    4 20  7 3 . . . . . . . . . . . . . .
    5  1  7 . . . . . . . . . . . . . . .
    5  3  3 . . . . . . . . . . . . . . .
    5  4  5 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    5  5  4 3 1 . . . . . . . . . . . . .
    5  6  5 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    5  7  5 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    5  9  3 . . . . . . . . . . . . . . .
    5 10  4 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    5 13  3 . . . . . . . . . . . . . . .
    5 14  6 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    5 18  5 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    5 20  6 3 . . . . . . . . . . . . . .
    6  2  7 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    6  4  5 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    6  5  5 . . . . . . . . . . . . . . .
    6  6  4 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    6  7  5 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    6  8  6 . . . . . . . . . . . . . . .
    6  9  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    6 11  5 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    6 12  6 . . . . . . . . . . . . . . .
    6 13  7 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    6 14 10 2 . . . . . . . . . . . . . .
    6 15  3 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    6 16  8 1 . . . 0 0 0 0 0 0 0 0 0 0 0
    6 17  3 . . . . . . . . . . . . . . .
    6 18  4 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0
    6 19  5 . . . . . . . . . . . . . . .
    6 20  4 3 . . . . . . . . . . . . . .
    end
    label values FL28 labels215
    label def labels215 1 "COMPLETED", modify
    label def labels215 2 "NOT AT HOME", modify
    label def labels215 3 "MOTHER / CARETAKER REFUSED", modify
    label def labels215 5 "PARTLY COMPLETED", modify
    label values FL19W2 labels129
    label def labels129 0 "CORRECT", modify
    label def labels129 1 "INCORRECT", modify
    label values FL19W71 labels198
    label def labels198 2 "NOT REACHED", modify
    label values FL19W72 labels199
    label def labels199 2 "NOT REACHED", modify
    Last edited by Shahla Akram; 19 Jul 2023, 18:02.

  • #2
    Well, I can tell you what the problem is, but I cannot guess what the solution might be.

    The problem is in the command -replace target=target+1 if FL19W`num'==" "-. The variables FLW19* are all numeric variables taking values like 0, 1, 2, or (mostly) missing. It is not possible to compare them to -" "-, which is a string containing a blank space. You can only compare strings to strings or numeric expressions to numeric expressions. So the question is what is supposed to be there instead of " " in that command. It must be one of the possible values of the FL19W* variables, or perhaps numeric missing value (.). But I don't understand the purpose of the code and the meaning of these variables well enough to tell you which.

    Comment


    • #3
      I am interested in utilizing fl19w to calculate a singular new variable that indicates the number of correctly read words. For example, if an individual has 60 words, this variable will represent the count of words read correctly by that child. Similarly, for another individual who reads 30 words correctly, and a third individual who reads 72 words correctly, this variable will accurately reflect their respective performances. Could you please provide guidance on how to perform this calculation?

      Comment


      • #4
        Judging from the value labels defined for the FL19W* variables, it seems like the code for correct is 0. So it should be:
        Code:
        replace target=target+1 if FL19W`num'== 0

        Comment


        • #5
          Thanks A lot Clyde it really work

          Comment

          Working...
          X