Hi everyone,
I have student scores for two test components (Component1 & Component2) from 485 schools. Using a linear regression model of Component1 on Component2, I want to predict scores for students who missed Component1 or whose marks were not recorded. The regression equation will be school-specific and used to generate predicted scores, recorded in a variable called "Predicted_Scores." The plan is for Stata to regress Component1 on Component2, predict missing Component1 scores for each school one-by-one, and store the predictions in a single variable named "Predicted_Scores." I've written the code bellow to accomplish this, but Stata is applying the same regression coefficients to all schools. Can you assist me in resolving this issue?
Code:
gen Predicted_Scores = .
forvalues i = 1/ 485 {
regress Component1 Component2 i.School_Code if School_Code == `i'
predict predicted_values, xb
replace Predicted_Scores = predicted_values if School_Code == `i'
}
Related Posts with Predicting values using Simple Linear Regression on Categorical Data
esttab produces redundant table openings &\multicolumns{}, when looping and appending regression results, that can not be suppressedDear Ben Jann, I am very much thankful for all the scripts and packages that you have written so fa…
defining a new variable such that one variable (string) in another variable?Dear All, Suppose that I have the data Code: * Example generated by -dataex-. To install: ssc insta…
generating observation "scores" after Mokken analysisDear all, I am conducting a Mokken scale analysis using loevh, with the following syntax: Code: lo…
no observations r(2000)Hi, I'm trying to make a regression on a panel dataset, but this ---no observations r(2000);--- I a…
Generating new variables, sorted from a varlistI've been puzzling with this problem for hours, but I can't figure it out. Per observation, I need t…
Subscribe to:
Post Comments (Atom)
0 Response to Predicting values using Simple Linear Regression on Categorical Data
Post a Comment