I want to create a new variable called predicted_scores that contains the predicted scores of RMarks_P1 for each school. There are 485 schools in total (categorical variable labeled as Centre_code). To do this, I run a separate regression of RMarks_P1 on RMarks_P2 for each school and use the school-specific regression equation to generate the predicted scores. I have written this code below. The challenge is that, only predicted values for one school are being replaced in the variable predicted_scores. Kindly help
gen predicted_scores = .
forvalues i = 1/485 {
regress RMarks_P1 RMarks_P2 i.Centre_Code if Centre_Code == `i'
predict predicted_values, xb
replace predicted_scores = predicted_values if Centre_Code == `i'
}
The link to my dataset 👇👇
https://1drv.ms/u/s!AiOobe2LyVvDhO9d...1kB8A?e=SOcrrf
gen predicted_scores = .
forvalues i = 1/485 {
regress RMarks_P1 RMarks_P2 i.Centre_Code if Centre_Code == `i'
predict predicted_values, xb
replace predicted_scores = predicted_values if Centre_Code == `i'
}
The link to my dataset 👇👇
https://1drv.ms/u/s!AiOobe2LyVvDhO9d...1kB8A?e=SOcrrf
Comment