One situation in which you can do so is after time-related prepositions, such as in your sentence. Other examples in involving time-related prepositions: “After I ate dinner I went to sleep.” = “After eating dinner I went to sleep”. “Before you cross the street, look both directions” = “Before crossing the street, look both directions.”