That's like saying that being a computer programmer is immoral, because if everyone would become a computer programmer, no one would cultivate food, and within a month the humanity would vanish.
It's possible to make a more complex algorithm saying that those who have a comparative advantage in computer programming should become computer programmers and those who have a comparative advantage in cultivating food should cultivate food. This way humanity can survive.
Analogically we should be thinking about consequences of a world where people with a comparative advantage in donating don't have children and instead donate the money to efficient charities, and some other people have children and ensure that humanity survives. -- There are some things that could go wrong in that scenario, but it's not that trivially wrong.
(Also, it is important to note that most people don't behave according to Kant's rules, so even a strategy that would maximize global utility if everyone used it, is not necessarily the global utility maximizing choice for an individual in real life.)
EDIT: I am not deeply familiar with Kant's philosophy. It just seems to me that it makes sense to seek an algorithm that maximizes global utility when used by everyone, but it would be stupid to require that the algorithm produce the same output for everyone. If two people have different comparative advantages, they can both use an algorithm "do what is your comparative advantage and trade with the other person", and yet their behavior will not be identical. Children are valuable, in my opinion; the topic of this discussion is that maybe some people can create a lot more value by doing something else.
From Daniel's post, it seems like the categorical imperative defines whether some behavior could be considered morally required, not whether a particular behavior is immoral. Being a computer programmer couldn't be morally required of everyone, but that doesn't mean that it is immoral for some people to be computer programmers.
In "The Immorality of Having Children" (2013, pdf) Rachels presents the "Famine Relief Argument against Having Children":
They present this as a special case of Peter Singer's argument from Famine, Affluence, and Morality (1972), which is why they haven't called it something more reasonable like the "Opportunity Cost Argument".
[Note: the use of "Famine Relief" here is in reference to Peter Singer's 1972 example, but famine relief is not where your money does the most good. Treat the argument as "that money would be far better spent on GiveWell's top charities" or whatever organization you think is most effective.]
It's true that having and raising a child is very expensive. They use an estimate of $227k for the direct expenditure through age 18 while noting that college [1] and time costs could make this much higher. Let's use a higher estimate of $500k to account for these. Considered over twenty years, that's $25k/year or $2k/month. This puts it at the top of the range of expenses, next to housing. It's also true that this money can do a lot of good when spent on effective charities. At GiveWell's current best estimate of $2.3k this is enough money to save nearly one life per month. [2]
But perhaps we shouldn't be thinking of this money as an expense at all, and instead more as an investment? Could having kids be a contender for the most effective charity? That is, could having and raising kids be one of the most effective things you could do with your time and money?
For example you could convince your kid to be unusually generous, donating far more than they cost to raise. Except that it's much cheaper to convince other people's kids to be generous, and our influence on the adult behavior of our children is not that big. Alternatively, if you're unusually smart, by having kids you could help make there be more smart people in the future. But how many more generations will pass before we learn enough about the genetics of intelligence to make this aspect of parental genetics irrelevant? Rachels considers the idea that your having children might greatly benefit the world, and rightly finds it insufficient. While your child may do a lot of good, for the expense there are much better options. Having kids is not a contender for the most effective charity, or even very close.
Having kids is a special case of spending your time and money in ways that make you happy. A moral system for human beings needs to allow some amount of this. It's like working for $56k at a job you enjoy instead of getting $72k at a job you like less. [3] Or spending your free time reading instead of working extra hours building up a consulting business. Keeping in mind both the cost and that on average people don't seem to be happier parenting, if having kids is what would make you most happy for the expense in time and money then it seems justified.
(This is how Julia and I thought of it when deciding whether we should have kids.)
I also posted this on my blog.
[1] College is currently in a huge state of flux. Advertised costs are rising far faster than inflation as colleges realize they can get away with near perfect price discrimination in the form of "either pay the extremely high sticker price or give us all your financial data so we can determine exactly how much you can afford." At the same time online courses and mixed models are getting to where they can provide much of the value of traditional lecture courses, and in some ways do better. I have very little idea what to budget for college for a kid born now; likely costs range from "free" to "all you have".
[2] Rachels uses a much lower number:
Their Brenzel citation is to the Vaccine-Preventable Diseases section of the DCP2. The $205 number is "Estimated cost per death averted for the Traditional Immunization Program in Sub-Saharan Africa and South Asia" in table 20.5.
[3] This is a $16k difference, which comes from taking $500k over 20 years and dividing by two for the two parents, and then adding some for taxes. Though the earnings difference is likely to last more like 40 years.