Gtools Macro -

* Verify variable exists confirm variable `oldvar'

program define gtools_macro version 15 syntax [varlist] [if] [in] [, /// RECode(numlist) /// GENerate(string) /// LABel(string) /// CUTpoints(numlist) /// BINs(integer 5) /// STDize /// LOG /// SQRT /// SQUare /// RANK /// Center /// PErcentile(integer 10) /// TOPcode(real 99) /// BOTtomcode(real 1) /// MISSing(real .) /// REPLace /// DROPold /// VERBose /// SAVe(string) /// APPend(string) /// STATistics /// HELP /// ] gtools macro

* Help display if "`help'" != "" di as text _n "gtools_macro - Comprehensive data transformation tool" di as text "==================================================" di as text "Options:" di as text " recode(numlist) - Recode values (e.g., 1/5=1 6/10=2)" di as text " generate(string) - Name of new variable" di as text " label(string) - Variable label for new variable" di as text " cutpoints(numlist)- Cut points for binning" di as text " bins(#) - Number of equal-width bins (default: 5)" di as text " stdize - Standardize to mean 0, sd 1" di as text " log - Natural log transformation" di as text " sqrt - Square root transformation" di as text " square - Square transformation" di as text " rank - Rank transformation" di as text " center - Center by subtracting mean" di as text " percentile(#) - Create percentile groups" di as text " topcode(#) - Topcode values above #" di as text " bottomcode(#) - Bottomcode values below #" di as text " missing(#) - Set specific value to missing" di as text " replace - Replace existing variable" di as text " dropold - Drop original variable" di as text " verbose - Display detailed output" di as text " save(filename) - Save results to file" di as text " append(filename) - Append results to file" di as text " statistics - Show summary statistics" exit * Verify variable exists confirm variable `oldvar' program

* Determine new variable name if "`generate'" == "" & "`replace'" == "" local newvar = "`oldvar'_transformed" else if "`generate'" != "" local newvar = "`generate'" else if "`replace'" != "" local newvar = "`oldvar'" Version 1

* Check if varlist provided if "`varlist'" == "" di as error "Error: varlist required" exit 198

*! gtools_macro.ado *! Full-featured data transformation and recoding tool *! Version 1.0

* Temporary variable for calculations tempvar tempvar * Apply if/in conditions marksample touse, novarlist mark `touse' `if' `in' * Create initial copy quietly gen `tempvar' = `oldvar' if `touse'