๐ Endogeneity Testing Across Multiple Outcome Variables (Stata)
Iโve recently run a systematic endogeneity check across all my key dependent variables using IV regression. The idea is to test whether fertility_rate is endogenous in explaining different wellbeing outcomes.
๐ Outcome variables used:
dv_phy
dv_sex
Emotional_Index
dv_overall_index_pct
โ๏ธ Stata Code:
*========================================
* ENDOGENEITY TESTS FOR ALL DEPENDENT VARIABLES
*========================================
global outcomes dv_phy dv_sex Emotional_Index dv_overall_index_pct
foreach y of global outcomes {
ivreg2 `y' $controls (fertility_rate = $IV_both), ///
endog(fertility_rate) cluster(cluster)
outreg2 using "$Results/Endogeneity_All_Outcomes.xls", ///
append ctitle("Endogeneity Test: `y'")
}
๐ What this does:
Runs IV regression for each outcome variable in a loop
Tests whether fertility_rate is endogenous
Uses clustered standard errors
Stores results in a single Excel file for comparison
This approach keeps the analysis clean, scalable, and consistent across multiple outcomes.
If anyone is doing similar multi-outcome IV work, this loop-based structure is very efficient.
QuantLab
Contact information, map and directions, contact form, opening hours, services, ratings, photos, videos and announcements from QuantLab, Educational Research Center, Khulna.
01/05/2026
๐๐จ๐จ๐ค๐ข๐ง๐ ๐ญ๐จ ๐ฅ๐๐ฏ๐๐ฅ ๐ฎ๐ฉ ๐ฒ๐จ๐ฎ๐ซ ๐๐๐ซ๐๐๐ซ?โฃ
โฃ
๐ Join our Hands-on Stata Training and learn data analysis the easy way! โฃ
โฃ
This intensive course focuses on the practical essentials: data cleaning, visualization, and analysis to help you in shaping real-world data for report writing. Limited seats only, so don't miss out! โฃ
โฃ
๐ ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐๐จ๐ฐ: https://forms.gle/aaJPUqeYpcJqGLHc6
25/12/2025
Glad to share that I have received two reviewer certificates from Springer Nature for evaluating manuscripts in Humanities and Social Sciences Communications and Discover Sustainability in 2025. Grateful for the opportunity to contribute to high-quality, impactful research through the peer-review process.
๐ Just discovered a neat trick in Stata!
If you want your graphs to look clean, simple, and publication-ready, try this:
grstyle init
grstyle set plain
This removes all the extra colors, grids, and decorations, giving your graphs a plain and professional look. Perfect for presentations or reports! โ
๐น Stata Tip of the Day: floor() Command ๐น
Ever needed to round numbers down to the nearest whole number in Stata?
The floor() function is what you need! ๐งฎ
โ
Syntax:
generate newvar = floor(oldvar)
๐ Example:
If oldvar = 12.8 โ floor(oldvar) = 12
If oldvar = -3.2 โ floor(oldvar) = -4
๐ก Use this when dealing with age grouping, income brackets, or intervals where you need consistent rounding down.
19/10/2025
1) Short & friendly (quick share)
Want quick summary stats in Stata? โจ Use collapse. It converts your dataset to aggregated values (means, sums, counts) โ e.g. collapse (mean) income, by(village) gives village-level average income.
Tip: preserve + restore if you donโt want to lose the original data. ๐พ
2) Technical post for researchers (copy-paste ready)
Stata quick-tip: collapse aggregates your dataset into summary-level observations โ very handy for moving from household to village or individual to group-level analysis.
Example (village-level averages & counts):
* keep original data (safe practice)
preserve
* village-level mean of income and mean of education,
* and count of households per village
collapse (mean) income education (count) household_id, by(village_id)
* now dataset contains one row per village with mean income, mean education, and household count
* restore the original dataset if needed
restore
Useful variants:
(sum) for totals, (median) for medians, (sd) for standard deviation.
Always preserve/restore or save to a new file โ collapse replaces your data in memory.
Sharing because small commands save so much time! ๐ก
3) Mini-tutorial (step-by-step for a post)
Want aggregated data fast? Use collapse in Stata โ it reduces rows by computing stats like means, sums, medians, counts.
Step example (create village-level totals & averages):
* 1) Save original (optional but recommended)
preserve
* 2) Aggregate: village totals for births and average income
collapse (sum) births (mean) income, by(village)
* 3) Work with aggregated data...
list in 1/10
* 4) Return to original data
restore
Reminder: collapse replaces your dataset in memory. Use preserve/restore or save the collapsed file with save collapsed_village.dta, replace. ๐
If anyone wants a short video or a do-nothing-but-try-it example with their own dataset, tell me which vars & Iโll craft it! ๐
Collapse command in stata Learn how to use the collapse command in Stata to summarize your data efficiently. This tutorial covers the basics of collapsing datasets by mean, sum, count...
๐ฏ Stata Tip: Difference between gen and egen
If youโre new to Stata, you might wonder โ whatโs the difference between gen and egen?
๐ gen (generate)
Used to create a new variable based on simple expressions or calculations within each observation.
Example:
gen income_per_capita = income / household_size
๐น Works observation by observation.
๐น Great for arithmetic or logical operations.
๐ egen (extensions of generate)
Used for more complex functions, especially those that require group-level calculations or summary statistics.
Example:
egen avg_income = mean(income), by(village)
๐น Works across observations (e.g., group means, ranks, counts).
๐น Comes with many built-in functions that gen canโt do.
โ
In short:
gen โ simple calculations (row-wise)
egen โ advanced calculations (group-wise or across data)
๐ STATA Quick Tip: Sorting Your Data Like a Pro!
Need to organize your dataset?
Hereโs how to use sort and gsort in Stata ๐
๐น Ascending Order (A โ Z / Small โ Large)
sort year
๐น Sort by Multiple Variables
sort country year
๐น Descending Order (Z โ A / Large โ Small)
gsort -year
๐น Mixed Order Sorting
gsort country -year
๐ก Tip:
Use gsort when you want full control โ like sorting newest years first or ranking by income highest to lowest.
clear
input str10 country year gdp
"Bangladesh" 2020 425
"Bangladesh" 2015 340
"Nepal" 2021 150
"Nepal" 2018 120
end
* Sort by country (asc) and year (desc)
gsort country -year
๐ก Stata Tip of the Day!
Ever wanted to remove specific observations quickly without typing a long list of conditions?
Try using the inlist() function โ it makes your code short, clean, and powerful! โก
๐ Example:
drop if inlist(ID, 238, 239, 240, 241, 242)
โ
What it does:
This command drops all observations where the variable ID matches any of those listed values.
No need to repeat ID == ... multiple times! Just wrap them in inlist(), and Stata does the rest.
Keep your code neat, readable, and efficient โ thatโs the Stata way! ๐ปโจ
Click here to claim your Sponsored Listing.