No, you do not have to pay tax if you sell shares or stocks and reinvest the capital gains in an eligible capital asset. Under section 54F you can invest the capital gain and buy a residential house property. Also, the amount invested will be exempt from capital gains.