Exactly..."so far from God, so near the United States"
I think everyone is overestimating the importance of the northern territories, except perhaps California. What screwed Mexico was not losing what amounts to a large amount of empty desert, but rather decades of civil war and internal unstability.
For several decades after 1821, when the Spanish imperial territory of New Spain became independent as the nation state of Mexico, the country's politics were the archetype of instability - governments came and went at the point of a caudillo's gun, and that instability placed the nation's territorial integrity at risk, repeatedly.
That instability grew directly from the consequences of the Mexican Revolution against Spain, which had begun in 1810 (or, arguably, in 1808, with the pro-Spanish coup d'etat against the then-viceroy, Jose Iturrigaray, and continued into 1809, with Obeso's and Santa Maria's abortive rising); just to put things into perspective, based on von Humboldt's work, the population of New Spain in 1803 was (roughly) 6 million; of these, about 200,000 were European (of both peninsulare and criollo nativity), about 3 million were mestizo (with varying levels of assimilation into a "Mexican" identity), and about 2.7 were native peoples, again of widely mixed assimilation and acculturation.
The war broke out for real in 1810, under the leadership (essentially) of Miguel Hidalgo; the conflict rapidly became one that pitted factions of Mexican liberals against Mexican conservatives, with Spanish royalist support (or vice-versa) for the conservatives. In 1821, independence came, although in this case, those who took power were (for the most part) former royalist criollos, including Iturbide; Iturbide's "empire" rapidly followed, and lasted until 1823; the resultant weak and fragmented republic was invaded by Spain again in 1829, which brought Santa Anna into public life as a war hero; he manipulated Mexican politics for the next quarter-century, holding office no less than nine times and backing figureheads repeatedly when he was not in office.
Essentially, the Royalist "criollo" army was the cadre of the Mexican nation state, in its imperial and republic guises; this led to the conservative dominance of Mexican politics for the next century. As an example, of the 188 generals and colonels on the Mexican Army's register in 1840, 81 one had begun their careers in the Spanish army - of the 16 general officers in the Mexican Army in 1823, only two had been revolutionaries of note, Vincente Guerrero and Nicolas Bravo. Along with the army, the other power base in Mexico was the Church, which may have controlled as much as 50 percent of the nation's arable land, even after independence.
During the four decades from 1821 to 1861, Mexico had at least 50 separate presidencies, each lasting for less than one year; 35 of these administrations were led by serving army officers. Worth noting that there were almost 600 separate cabinet appointments in the same period, but they went to only 207 invdividuals.
The other element in play of the loss of population and wealth; Mexico's population was estimated at 4 million in 1821; the revenue that had gone to the central government had dropped by 80 percent. As an example, Valenciana, one of the rich mining towns in what is today Guanajuato, dropped from 22,000 people in 1810 to 4,000 in 1820. Some 15 to 30 percent of the male working age population, most of them veterans, were unemployed, and many turned to caudilloism; in addition, with the departure of many of the Spanish-born in the 1820s, a large percentage of the professional classes were lost, which did not help with economic recovery. It took until 1850 for the population to reach 7.6 million.
Basically, with the deaths of Hidalgo in 1811 and Morelos in 1815, the possibility of a liberal-nationalist revolution was pretty much gone; the last gasp was Vicente Guerrero's presidency in 1829, and he was overthrown by Anastasio Bustamante, who served as president from 1830 to 1832, from 1837 to 1839 and from 1839 to 1841, and was deposed twice.
So, realistically, 1840 is too late; basically, if Obeso and Santa Maria had succeeded in 1810, and brought men like Hidalgo, Morelos, and Guererro into the revolution by 1815 or so, there's a chance the decades of instability could have been avoided, and Mexico could have gotten into the era of national consolidation 40 years earlier than historically...but it's only a chance.
Sad but true.
Best,