I'm looking to use an independent group t-test to compare the difference between students' grade estimates and their assigned grades (variable: gradempre) in one course against that of another course (variable: CourseID).

I've tried using:
ttest gradempre if CourseID==1, by(gradempre if CourseID==2)

to no avail. Of course I could assign the two courses' gradempre values as different variables...but I'm looking to do this kind of kind of comparison a number of times (and it feels like a good thing to know how to do!).

Any advice is much appreciated! Thank you.

System info:
Stata 15.1 for Windows (running Win10)