Announcement

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

  • inquire a code problem about operator operation

    Code:
    * first generation undergraduates
    label define q28 1 "High School or equivalent" ///
                     2 "Some College or 2 year degree" ///
                     3 "Bachelor's Degree or a 4-year college degree" ///
                     4 "Master's Degree or Advanced Degree" ,modify
    
    label define q29 1 "High School or equivalent" ///
                     2 "Some College or 2 year degree" ///
                     3 "Bachelor's Degree or a 4-year college degree" ///
                     4 "Master's Degree or Advanced Degree" ,modify
    
    label values q28 Mom_Highest_edu
    label values q29 Dad_Highest_edu
    describe q28 q29
    label list q28 q29
    
    generate first_generation = (q28==1 | 2) & (q29==1 | 2) 
    
    
    label variable first_generation "First Generation Students"
    label define firstgen 1 "First Generation in College" ///
                          0 "Non First Generation"
    label values first_generation firstgen
    My idea is that I want to find those students who are first generation students. The definition is that both parents who did not complete bachelor degree. Thus, if both q28 and q29 are equal to 1 or 2, then this student is first generation student. Thus, my code is designed as
    Code:
    generate first_generation = (q28==1 | 2) & (q29==1 | 2)
    But the outcome is incorrect.

  • #2
    Maybe try
    Code:
    generate byte first_generation = inlist(q28, 1, 2) | inlist(q29, 1, 2)

    Comment


    • #3
      Yes, this code is correct (expect change | to &)! There is also another correct code:
      Code:
      generate first_generation = (q28==1 | q28==2) & (q29==1 | q29==2)
      My questions for your code are:
      1. Is it common for researchers to add "byte" after "generate"?
      2. Could you tell me more details about "inlist"?

      Many thanks in advance!

      Comment


      • #4
        Originally posted by Yao Zhao View Post
        My questions for your code are:
        1. Is it common for researchers to add "byte" after "generate"?
        2. Could you tell me more details about "inlist"?
        I don't know what researchers do when they write production code in a controlled environment, but I suspect that in general they pay adequate attention to type. On this list, most participants are happy to go with the default single-precision floating point data type for nearly everything.

        You can find out more about any official Stata function, such as inlist() in the documentation. At Stata's command prompt, type
        Code:
        help inlist()
        for more information in the screen that pops up, which includes a hyperlink to the corresponding user's manual entry.

        Comment

        Working...
        X