Do-file β€” Stata da takrorlanuvchi tahlillarni avtomatlashtirish vositasi.

Do-file tuzilishi

*==========================================
* Loyiha: SQL.uz tahlil
* Muallif: Sherali Rahimov
* Sana: 2026-06-16
*==========================================

clear all
set more off
capture log close

* Papkalarni sozlash
global root   "C:/Loyiha"
global data   "$root/data"
global output "$root/output"
global log    "$root/log"

log using "$log/tahlil.log", replace

* Ma'lumot yuklash
use "$data/asosiy.dta", clear

* ... tahlil ...

log close

Makrolar

* Local makro (faqat joriy do-file da)
local o'zgaruvchilar "yosh maosh ta'lim_yil"
summarize `o'zgaruvchilar'

* Global makro (hamma joyda)
global boshqaruvchilar "yosh ta'lim_yil jinsi shahar_id"
regress maosh $boshqaruvchilar

* Makrodan foydalanish
local n = _N
di "Kuzatuvlar soni: `n'"

Tsikl (Loop)

* Ro'yxat bo'yicha
foreach var in yosh maosh ball {
    summarize `var'
    histogram `var', saving("hist_`var'.gph", replace)
}

* Son oraliqda
forvalues y = 2020/2024 {
    use "$data/ma'lumot_`y'.dta", clear
    summarize
    save "$output/tozalangan_`y'.dta", replace
}

* While tsikl
local i = 1
while `i' <= 5 {
    di "Qadam: `i'"
    local ++i
}

Shartlar

if "`method'" == "ols" {
    regress maosh $boshqaruvchilar
}
else if "`method'" == "robust" {
    regress maosh $boshqaruvchilar, robust
}
else {
    di as error "Noma'lum usul: `method'"
}

Capture β€” xatolarni ushlash

* Xato bo'lsa ham davom etish
capture drop yangi_ustun
capture mkdir "$output"

* Xato kodini tekshirish
capture confirm file "fayl.dta"
if _rc == 0 {
    di "Fayl mavjud"
}
else {
    di "Fayl yo'q"
}

Program β€” o'z buyrug'ingizni yarating

program define my_reg, eclass
    syntax varlist [if] [in] [, Robust]

    gettoken dep indep : varlist

    if "`robust'" != "" {
        regress `dep' `indep' `if' `in', robust
    }
    else {
        regress `dep' `indep' `if' `in'
    }
end

* Ishlatish
my_reg maosh yosh ta'lim_yil, robust