1 - locate the verb (wrote).
2 - place the object (Hamlet) at the beginning of the new sentence, as the new subject.
3 - transform the verb into passive ( verb to be in the same verbe tense + -ed/3rd col.).
4 - place the original subject (Shakespeare) after the transformed verb and the preposition by. If the subject is not relevant (they, someone, everyone...) we don't need to include it.