Gtools Macro 🆕 Extended

* Parse variable list - use first variable only tokenize `varlist' local oldvar = "`1'"

* 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 gtools macro

* Check if variable exists if "`replace'" == "" capture confirm new variable `newvar' if _rc != 0 di as error "Variable `newvar' already exists. Use replace option." exit 198 * Parse variable list - use first variable

* 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' gtools macro