Not sure if there is a service to buy and/or trade cell phone numbers.
In theory, anything is possible, but it is very unlikely that T-Mobile will do that. The problem is that two lines that are owned by two different people being able to join accounts into a family plan is very confusing on a legal basis. Someone would have to be the primary holder. Which means your friend will be controlling your destiny as it pertains to your "so called" phone line.
For instance you and your friend may be the best of friends (practically siblings) but let's say for whatever reason you are unable to pay your portion of the bill, your friend will be left to pay your portion and I'm sure your friend would be posting on this Forum his frustration of being charged early termination fees, ruining his credit because the unpaid portion went into collections, and during all of this circus fiasco you will realize that T-Mobile should never have allowed this to happen.
Let's rewind back to the present day. Now if your friend start an extra line on their account and allows you to use it is an entirely different matter. But you would have to use whatever number that was assigned to that phone. And Because your friend would have already assumed all of the responsibilities for having that extra line and any litigation against them would be justified if the bill doesn't get paid ontime. Your friend would be unable to play the blame game.
This entire idea sounds like a nightmare waiting to occur, and if it was possible to do what you would like to do, I would advise against it 100% .