/* parqit generate - Create a new variable, or change the contents of a variable *! VERSION 0.1.37 07sep2026 User > parqit > Create or change variables... Launch directly with: db parqit_gen (menu installed by: parqit menu) Builds parqit gen / egen / replace. Both Create... buttons open Stata's expression builder (dates via td(), tm(), year(), mdy(), ...). An untyped result is stored as double; choose a type to control storage, exactly like a typed native generate. Lazy: the view's plan changes, not the data in memory. */ VERSION 16.0 INCLUDE _std_wide DEFINE _dlght 380 INCLUDE header HELP hlp1, view("help parqit##expressions") RESET res1 SCRIPT PREINIT BEGIN create STRING dlgname dlgname.storeDialogClassName create DOUBLE pq_populate_error END PROGRAM POSTINIT_PROGRAM BEGIN call program main_mode call program main_context END DIALOG main, label("parqit generate - Create a new variable, or change the contents of a variable") /// tabtitle("Main") BEGIN RADIO rb_gen _lft _top _iwd ., /// first /// onclickon(program main_mode) /// label("Create a new variable (generate)") RADIO rb_egen @ _ss @ ., /// onclickon(program main_mode) /// label("Create a new variable by group (egen)") RADIO rb_repl @ _ss @ ., /// last /// onclickon(program main_mode) /// label("Change contents of a variable (replace)") TEXT tx_type _lft _ls _vnwd ., /// label("Variable type:") TEXT tx_name 140 @ 160 ., /// label("Variable name:") TEXT tx_fcn 310 @ 120 ., /// label("egen function:") BUTTON bu_pop _rj80 @ 80 ., /// onpush(program main_populate) /// tooltip("Populate the by() combobox with the variable names of the current view") /// label("Populate") COMBOBOX cb_type _lft _ss _vnwd ., /// dropdown /// contents(type_list) /// default("(double)") /// label("Variable type") EDIT ed_name 140 @ 160 ., /// max(32) /// error("Variable name") /// label("Variable name") COMBOBOX cb_fcn 310 @ _vnwd ., /// dropdownlist /// contents(fcn_list) /// default("mean") /// label("egen function") TEXT tx_exp _lft _ls _iwd ., /// label("Expression (dates as td(01jan2015), year(x), ...):") EXP ex_exp @ _ss @ ., /// error("Expression") /// label("Create...") TEXT tx_if _lft _ls _iwd ., /// label("If (expression) (optional; generate and replace only):") EXP ex_if @ _ss @ ., /// label("Create...") TEXT tx_by _lft _ls _iwd ., /// label("Group variables for egen, option by() (optional):") COMBOBOX cb_by @ _ss @ ., /// append /// dropdown /// contents(vv_list) /// option(by) /// label("Group variables") TEXT tx_note _lft _ls _iwd ., /// label("An untyped result is stored as double (native generate defaults to float); choose a type to control storage.") TEXT tx_context _lft 335 470 ., label("Current view: refresh to check") BUTTON bu_context _rj80 @ 80 ., label("Refresh") onpush(program main_populate) END PROGRAM main_context BEGIN put "parqit _dlgcontext " put dlgname stata hidden queue clear END LIST vv_list BEGIN END LIST type_list BEGIN "(double)" byte int long float double str8 strL END LIST fcn_list BEGIN total mean sd min max count END PROGRAM main_mode BEGIN if main.rb_gen { call main.tx_type.enable call main.cb_type.enable call main.tx_fcn.disable call main.cb_fcn.disable call main.tx_if.enable call main.ex_if.enable call main.tx_by.disable call main.cb_by.disable call main.bu_pop.disable } if main.rb_egen { call main.tx_type.enable call main.cb_type.enable call main.tx_fcn.enable call main.cb_fcn.enable call main.tx_if.disable call main.ex_if.disable call main.tx_by.enable call main.cb_by.enable call main.bu_pop.enable } if main.rb_repl { call main.tx_type.disable call main.cb_type.disable call main.tx_fcn.disable call main.cb_fcn.disable call main.tx_if.enable call main.ex_if.enable call main.tx_by.disable call main.cb_by.disable call main.bu_pop.disable } END PROGRAM main_populate BEGIN call program main_context call pq_populate_error.setvalue 0 put "parqit _dlgvars " put dlgname put " vv_list" stata hidden immediate if pq_populate_error { stopbox stop "Unable to get the variable names of the current view." /// "Open a view first (User > parqit > Read data...)." } call main.cb_by.repopulate END PROGRAM command BEGIN if main.rb_gen { put "parqit gen " if !main.cb_type.isdefault() { put main.cb_type " " } require main.ed_name put main.ed_name " = " require main.ex_exp put main.ex_exp if main.ex_if { put " if " main.ex_if } } if main.rb_egen { put "parqit egen " if !main.cb_type.isdefault() { put main.cb_type " " } require main.ed_name put main.ed_name " = " main.cb_fcn "(" require main.ex_exp put main.ex_exp ")" beginoptions optionarg main.cb_by endoptions } if main.rb_repl { put "parqit replace " require main.ed_name put main.ed_name " = " require main.ex_exp put main.ex_exp if main.ex_if { put " if " main.ex_if } } END