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
Markov switching for panel dataI want to estimate a Markov switching model for an unsustainable fiscal regime and a sustainable fis…
Calculate the age when the grant was received from the current age and the year when the grant was receivedDear All, Can you help me with the following. I have collected the age (d4) for all the respondent…
When to use Tobit regression?Hallo, I have been recommended to use a Tobit regression because my independent variable is very ri…
How do I detect if I have problem with my degree of freedom due to too many categorical variables in my regression model?I am aware that having too many categorical variables in the regression model might affect degree of…
How to add title to xlineCan you help me how I can specify the vertical line while I am using "twoway connected" command to s…
Subscribe to:
Post Comments (Atom)
0 Response to Predicting values using Simple Linear Regression on Categorical Data
Post a Comment