[verb (dictionary form)] + ことだ [verb ない-form] + ことだ
ことだ gives advice: "you should", "the thing to do is". It follows a verb in the dictionary form, or the ない-form for advice not to do something.
The advice comes from someone who knows better – a parent, a teacher, a doctor – and sounds like a rule of thumb. Said to a boss or a teacher, it is rude. The first half often sets up the goal with きごう〜たければ, きごう〜たいなら or きごう〜ためには. The polite form is ことです.
The verb stays in the dictionary form or the ない-form. A た-form turns the sentence into something else: ×行ったことだ.
After an adjective, ことだ is a different pattern: an exclamation, as in なん何とうれしいことだ, "how happy that makes me".