***** NOT A TEACHER *****
I am sure that I am just one of many members who are glad that the OP posted this question.
I have always been confused by which word to use with a gerund.
I went to Cambridge Dictionaries Online (which I guess can be considered reliable) and found their two examples.
IN (cause) To show when doing one thing is the cause of another thing.
1. "In refusing (= because she refused) to work abroad, she missed an excellent job opportunity."
2. "The government banned tobacco advertising and in doing so ( = because of that) contributed greatly to the nation's health."
I have a sneaking suspicion, however, that some people would feel equally comfortable with "by" in those sentences.
Oh, it's so confusing!