Announcement

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

  • Regressing two variables using the forvalues command and recording the predicted values in one variable

    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

    Click image for larger version

Name:	2023-04-17.png
Views:	1
Size:	232.6 KB
ID:	1710174

  • #2
    This isn't a Mata question. Please post in General, but before you do please read the FAQ Advice. Screenshots and links to datasets are not as helpful as you hope.

    Comment


    • #3
      Hello Cox,
      thank you for the guidance.

      Comment

      Working...
      X