And with more than 17,500 stores located within 5 miles of about 75% of the US population, we believe we are well positioned to continue supporting our customers through our unique combination of value and convenience.
As we continue to lap difficult quarterly sales comparisons from the prior-year, net sales decreased 0.4% to $8.7 billion, followed by a 24.4% increase in Q2 of 2020.
Comp sales declined 4.7% compared to the prior-year period, which translates into a robust 14.1% increase on a two-year stack basis.
As a reminder, gross profit in Q2 2020 was positively impacted by a significant increase in sales, including net sales growth of 41% in our combined non consumables categories.
For Q2 2021, gross profit as a percentage of sales was 31.6%, a decrease of 80 basis points, but an increase of 87 basis points compared to Q2 2019.
SG&A as a percentage of sales was 21.8%, an increase of 138 basis points.
Moving down the income statement, operating profit for the second quarter decreased 18.5% to $849.6 million.
As a percentage of sales, operating profit was 9.8%, a decrease of 219 basis points.
Our effective tax rate for the quarter was 21.4% and compares to 21.5% in the second quarter last year.
Finally earnings per share for the second quarter decreased 13.8% to $2.69, which reflects a compound annual growth rate of 27.7% or 24.3% compared to Q2 2019 adjusted earnings per share over a two-year period.
Merchandise inventories were $5.3 billion at the end of the second quarter, an increase of 20% overall and 13.7% on a per store basis, as we continue to cycle unusually low levels of inventory in Q2 2020 which were driven by extremely strong sales volumes in that quarter.
Year-to-date through Q2 we generated significant cash flow from operations totaling $1.3 billion.
Total capital expenditures for the quarter were $518 million and included our planned investments in new stores, remodels and relocations, distribution and transportation projects and spending related to our strategic initiatives.
During the quarter, we repurchased 3.3 million shares of our common stock for $700 million and paid a quarterly dividend of $0.42 per common share outstanding at a total cost of $98 million.
At the end of Q2, the remaining share repurchase authorization was $979 million.
We also remain committed to returning excess cash to shareholders through anticipated share repurchases in quarterly dividend payments, all while maintaining our current investment grade credit rating and managing to a leverage ratio of about 3 times adjusted debt-to-EBITDA.
Net sales growth of 0.5% to 1.5%; a same-store sales decline of 3.5% to 2.5% which reflects growth of approximately 13% to 14% on a two-year stack basis and earnings per share in the range of $9.60 to $10.20, which reflects a compound annual growth rate in the range of 20% to 24% or approximately 19% to 23% compared to 2019 adjusted earnings per share over a two-year period.
Our earnings per share guidance assumes an effective tax rate in the range of 22% to 22.5%.
With regards to share repurchases, we now expect to repurchase approximately $2.4 billion of our common stock this year, compared to our previous expectation of about $2.2 billion.
Finally, we are increasing our expectations for capital spending in 2021 to a range of $1.1 billion to $1.2 billion to reflect higher equipment costs for store projects in the pull forward of select supply chain investments.
Finally, please keep in mind that the third quarter represents our most challenging lap of the year from a gross profit rate perspective, following an improvement of 178 basis points in Q3 2020.
With regards to SG&A, we now expect about $70 million to $80 million of incremental year-over-year investments in our strategic initiatives as we further their rollouts.
This amount includes $40 million in incremental investments made during the first half of the year.
The NCI offering was available in more than 8,800 stores at the end of Q2, and we continue to be very pleased with the strong sales and margin performance we are seeing across our NCI store base.
In fact this performance is contributing to an incremental 1% to 2.5% total comp sales increase in NCI stores and a meaningful improvement in gross margin rate as compared to stores without the NCI offering.
Overall, we remain on track to expand this offering to a total of more than 11,000 stores by year-end, including over 2,100 stores in our light version, with the goal of completing the rollout of NCI across nearly the entire chain by year-end 2022.
POpshelf aims to engage customers by offering a fun, affordable and differentiated treasure hunt experience, delivered through continually refreshed merchandise, a differentiated in-store experience and exceptional value with the vast majority of our items priced at $5 or less.
During the quarter we opened eight new pOpshelf locations, bringing the total number of stores to 16, including four conversions of a traditional Dollar General store into our pOpshelf concept.
For 2021, we remain on track to have a total of up to 50 pOpshelf locations by year-end as well as up to an additional 25 store-within-a-store concepts as we continue to lay the foundation for future growth.
I'm very pleased to report that during the quarter, we completed the initial rollout of DG Fresh across the entire chain and are now delivering to more than 17,500 stores from 12 facilities.
For example, we recently introduced about 25 new and exclusive items under the Armor [Phonetic] brand, as we continue to optimize our assortment, while further differentiating our product offering from others.
And while produce was not included in our initial rollout plans, we believe DG Fresh provides a potential path to accelerating our produce offering in up to 10,000 stores over time as we look to further capitalize on our extensive self-distribution capabilities.
During the first half, we added more than 34,000 cooler doors across our store base and remain on track to install approximately 65,000 cooler doors this year.
In the second quarter, we completed a total of 772 real estate projects, including 270 new stores, 477 remodels and 25 relocations.
For the full year, we remain on track to open 1,050 new stores, remodel 1,750 stores and relocate 100 stores.
In addition, we now have produce in more than 1,500 stores with plans to expand this offering to a total of more than 2,000 stores by year end.
As a reminder, we recently made key changes to our development strategy, including establishing our larger 8,500 square foot format as our base prototype for nearly all new stores going forward.
In total, we expect to have nearly 2,000 stores in this format by the end of the year, as we look to further enhance our value and convenience proposition particularly in rural America.
In fact, we ended Q2 with nearly 4 million monthly active users on the app, a 28% increase over prior year.
Of note, during the first half, the number of campaigns on our platform increased 65% compared to the prior year period, and we are very excited about the growth potential of this business as we look to further enhance the value proposition for both our customers and brand partners.
Self checkout was available in approximately 4,300 stores at the end of Q2, and we continue to be pleased with our results, including customer adoption rates and higher overall satisfaction scores in stores that include this offering.
As evidenced, we recently launched a national hiring event with the goal of hiring up to an additional 50,000 employees by Labor Day, and I am pleased to note that we are on track to meet our goal.
We believe the opportunity to start and develop a career with a growing and purpose-driven company is a unique competitive advantage and remains our greatest currency in attracting and retaining talent, and because over 75% of our store associates at or above the lead sales associate position were internally placed, employees who joined Dollar General know, they have an opportunity to grow their career with us.
We also held our annual leadership meeting earlier this month, resulting in a rich and virtual development experience for more than 1,500 leaders of our company.

Summary:
As we continue to lap difficult quarterly sales comparisons from the prior-year, net sales decreased 0.4% to $8.7 billion, followed by a 24.4% increase in Q2 of 2020.
Comp sales declined 4.7% compared to the prior-year period, which translates into a robust 14.1% increase on a two-year stack basis.
Moving down the income statement, operating profit for the second quarter decreased 18.5% to $849.6 million.
Finally earnings per share for the second quarter decreased 13.8% to $2.69, which reflects a compound annual growth rate of 27.7% or 24.3% compared to Q2 2019 adjusted earnings per share over a two-year period.
Merchandise inventories were $5.3 billion at the end of the second quarter, an increase of 20% overall and 13.7% on a per store basis, as we continue to cycle unusually low levels of inventory in Q2 2020 which were driven by extremely strong sales volumes in that quarter.
Net sales growth of 0.5% to 1.5%; a same-store sales decline of 3.5% to 2.5% which reflects growth of approximately 13% to 14% on a two-year stack basis and earnings per share in the range of $9.60 to $10.20, which reflects a compound annual growth rate in the range of 20% to 24% or approximately 19% to 23% compared to 2019 adjusted earnings per share over a two-year period.