Announcement

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

  • How to create an indicator of total vocabulary score for bilingual children

    Hi all,

    I am using a dataset with vocabulary data for 5585 children who are 2 years old.

    We have a list of 100 words commonly spoken by 2 year olds which has been translated into 6 different languages. We asked parents to look at this list of 100 words and tick yes/no for the words that their child says in any of the 6 languages.

    I've attached a screenshot of a dummy dataset so you can see how the data is laid out in an example 13 cases, for 2 languages only (english and maori) and 3 words.

    For each of the 6 languages, each of the 100 words has its own variable:
    For example, for English and Maori, the variable names are: word_1_english, word_1_maori, word_2_english, word_2_maori,...word_100_english, word_100_maori.
    The possible responses are 0 (labelled "No") and 1 (labelled "Yes")

    I would like to create a score ("totalscore") out of 100 for the bilingual children (maorieng_y2cm == 1) that tells me how many of the 100 words the child knows in EITHER English or Maori, without double counting if a child knows the word in both languages.

    For instance,
    ID 200093, totalscore = 2
    ID 133593, totalscore = 3
    ID 249443, totalscore = 2
    ...
    ID 124223, totalscore = 3 (NOT 4)
    ID 120882, totalscore = 2 (NOT 3)

    If the child isn't bilingual (mooring_y2cm == .) then I want totalscore to stay as missing.

    I wondered about using the 'foreach' command, but I don't know enough state code to figure out how to code this
    Any help would be much appreciated!
    Click image for larger version

Name:	Screen Shot 2019-01-17 at 12.19.14 PM.png
Views:	1
Size:	86.7 KB
ID:	1479202

    Jin







  • #2
    Hi Jin,

    Please use dataex to share data (and not screenshots--they are very hard to read, especially if someone is reading from a phone). For help using dataex, there is a video tutorial here

    Code:
    * I created some toy data
    dataex id w1_eng w2_eng w3_eng w1_maori w2_maori w3_maori maorieng_y2cm  // Data shared via -dataex-. To install: ssc install dataex
    clear
    input byte(id w1_eng w2_eng w3_eng w1_maori w2_maori w3_maori maorieng_y2cm)
    1 0 1 0 1 1 1 1
    2 1 0 1 0 1 1 1
    3 1 0 1 1 1 1 1
    4 1 1 1 0 0 0 0
    5 1 1 0 0 0 0 0
    end
    ------------------ copy up to and including the previous line ------------------
    
    . list, noobs abbrev(15)
    
      +--------------------------------------------------------------------------------+
      | id   w1_eng   w2_eng   w3_eng   w1_maori   w2_maori   w3_maori   maorieng_y2cm |
      |--------------------------------------------------------------------------------|
      |  1        0        1        0          1          1          1               1 |
      |  2        1        0        1          0          1          1               1 |
      |  3        1        0        1          1          1          1               1 |
      |  4        1        1        1          0          0          0               0 |
      |  5        1        1        0          0          0          0               0 |
      +--------------------------------------------------------------------------------+
    
    egen total_eng = rowtotal(w*_eng) if maorieng_y2cm==1
    egen total_maori = rowtotal(w*_maori) if maorieng_y2cm==1
    
    * Loop here to count UNIQUE words (without double counting if a child knows the word in both languages)
    * Change i = 1/100 if words go from w1 to w100
    forvalues i = 1/3 {
    gen w`i' = max(w`i'_eng, w`i'_maori)
    }
    
    egen total_uniq = rowtotal(w1-w3)
    
    . list, noobs abbrev(15)
    
      +----------------------------------------------------------------------------------------------------------+
      | id   w1_eng   w2_eng   w3_eng   w1_maori   w2_maori   w3_maori   maorieng_y2cm   total_eng   total_maori |
      |----------------------------------------------------------------------------------------------------------|
      |  1        0        1        0          1          1          1               1           1             3 |
      |  2        1        0        1          0          1          1               1           2             2 |
      |  3        1        0        1          1          1          1               1           2             3 |
      |  4        1        1        1          0          0          0               0           .             . |
      |  5        1        1        0          0          0          0               0           .             . |
      +----------------------------------------------------------------------------------------------------------+
    
    * Just listing first 2 words to save space
    . list id w1_eng w1_maori w1 w2_eng w2_maori w2 maorieng_y2cm total_eng total_maori total_uniq , noobs abbrev(15)
    
      +-------------------------------------------------------------------------------------------------------------+
      | id   w1_eng   w1_maori   w1   w2_eng   w2_maori   w2   maorieng_y2cm   total_eng   total_maori   total_uniq |
      |-------------------------------------------------------------------------------------------------------------|
      |  1        0          1    1        1          1    1               1           1             3            3 |
      |  2        1          0    1        0          1    1               1           2             2            3 |
      |  3        1          1    1        0          1    1               1           2             3            3 |
      |  4        1          0    1        1          0    1               0           .             .            3 |
      |  5        1          0    1        1          0    1               0           .             .            2 |
      +-------------------------------------------------------------------------------------------------------------+
    
    * can replace total_uniq=. if maorieng_y2cm==0 if desired

    Comment


    • #3
      Dear David, thank you so much for this response. I have learnt a lot from it. I've adapted your code to my dataset and it's working perfectly. Thank you so much.

      Comment

      Working...
      X