gain (something) by (doing something)
To benefit in some way from doing something. Did you gain anything by picking a fight with your sister? I gained some peace of mind by finally telling the truth.
gain something by doing something
to achieve some benefit by doing something. What did he gain by dropping out of school? I will gain some degree of security by investing in U.S. Treasury bonds.