I found some sentences that in which by is not used. Such as:
- I did it myself .
- I will kill you myself .
- he cooks food himself.
Why by isn't used with these sentences like: by myself, by himself?
To be by yourself (note the preposition) means to be alone, or to have nobody else with yourself.
He stood by himself, as he was now completely alone
To do something yourself means that you are the only person carrying out a specified action.
Though the crowd offered their help, she insisted on doing it herself
If someone were to say "he cooks food by himself", that would most likely mean that they cook food alone.