Announcement

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

  • how to fix this kind of r(111) error?

    Hi, when I run the following code, in particular,
    Code:
    keep if attention_output_variable_`yvar' == 1
    it generates: variable attention_output_variable_`yvar' not found r(111).
    Any suggestion please?

    Code:
    global xvars "x y z"
    
    
    local i=0
    
     
    foreach yvar in ///
    shortrun_expenditure_ccc ///
    longrun_spending_ccc ///
    wage_total_ccc ///
    wage_income_ratio ///
    labour_wage_share_a_bb ///
    labour_efficiency_a_bb ///
    export_percent ///
    corporate_grosspr_aaa///
    corporate_totalrevenue_bbb ///
    corporate_noofpatents ///
    capacity_utilization_bbb ///
    capital_investment_ddd ///
    {
    
        local i=`i'+1
        di "                                                      "
        di "                                                      "
        di "************************ Outcome # `i'  **************"
        di "************************ `yvar'  **************"
    
        
    qui reg  `yvar' $xvars
    gen attention_output_variable_`yvar' = e(sample)
    }
    
    preserve
    keep if attention_output_variable_`yvar' == 1
    restore
    Last edited by Chul-Kyoo Jung; 15 Dec 2023, 12:44.

  • #2
    You are outside the loop of yvar. Doesn't know what you want.

    Comment


    • #3
      Thanks George, for some reason I cannot edit the original post. So here is what I want: I want to create a new variable that is used in my regression using e(sample). So the new variable is a dummy variable with 1 if it is used and 0 otherwise.
      And then I just want to save a new dataset which comprises all observations actually used in the regression. I did not put the command keep inside the loop because if so, you would not able to generate the new variable for the subsequent yvar. Please let me know if this does not sound clear to you.
      Last edited by Chul-Kyoo Jung; 15 Dec 2023, 14:18.

      Comment


      • #4
        Code:
        sysuse auto, clear
        
        global xvars headroom trunk weight
        
        foreach yvar in price mpg length {
            reg `yvar' $xvars
            preserve
            keep `yvar' $xvars
            keep if e(sample)
            save keepused_`yvar' , replace
            restore
        }

        Comment

        Working...
        X