/* parqit keep - Keep or drop observations, or draw a random sample *! VERSION 0.1.37 07sep2026 User > parqit > Keep or drop observations, or draw a sample... Launch directly with: db parqit_filter (menu installed by: parqit menu) Builds parqit keep if / drop if / keep in / drop in / sample. The Create... button opens Stata's expression builder (date functions td(), tm(), year(), ... included); Variables lists the names of the current view (parqit ds). These verbs are lazy: they change the view's plan, not the data in memory. */ VERSION 16.0 INCLUDE _std_wide DEFINE _dlght 355 INCLUDE header HELP hlp1, view("help parqit##verbs") RESET res1 SCRIPT PREINIT BEGIN create STRING dlgname dlgname.storeDialogClassName END PROGRAM POSTINIT_PROGRAM BEGIN call program main_mode call program main_context END DIALOG main, label("parqit keep - Keep or drop observations, or draw a random sample") /// tabtitle("Main") BEGIN RADIO rb_keepif _lft _top _lw80 ., /// first /// onclickon(program main_mode) /// label("Keep observations satisfying a condition (keep if)") BUTTON bu_ds _rj80 @ 80 ., /// onpush(program main_ds) /// tooltip("List the variable names of the current view (parqit ds)") /// label("Variables") RADIO rb_dropif _lft _ss _iwd ., /// onclickon(program main_mode) /// label("Drop observations satisfying a condition (drop if)") TEXT tx_if _ilft _ss _ibwd ., /// label("If (expression):") EXP ex_if @ _ss @ ., /// error("If (expression)") /// label("Create...") RADIO rb_keepin _lft _ls _iwd ., /// onclickon(program main_mode) /// label("Keep a range of observations of the pipeline result (keep in)") TEXT tx_from _ilft _ss 60 ., /// label("From:") right EDIT ed_from 85 @ 80 ., /// default(1) /// label("From") TEXT tx_to 170 @ 40 ., /// label("to:") right EDIT ed_to 215 @ 80 ., /// label("to") TEXT tx_fl _ilft _ss _ibwd ., /// label("Bounds may be numbers, f (first), l (last), or negative counts from the end (-1 is the last observation).") RADIO rb_dropin _lft _ss _iwd ., /// onclickon(program main_mode) /// label("Drop a range of observations of the pipeline result (drop in)") RADIO rb_sample _lft _ls _iwd ., /// last /// onclickon(program main_mode) /// label("Draw a random sample of the observations (sample)") TEXT tx_amount _ilft _ss 140 ., /// label("Amount:") right EDIT ed_amount 165 @ 80 ., /// error("Amount") /// label("Amount") CHECKBOX ck_count 255 @ 330 ., /// option(count) /// label("Amount is a number of observations, not a percentage (count)") TEXT tx_seed _ilft _ms 140 ., /// label("Random-number seed:") right EDIT ed_seed 165 @ 80 ., /// numonly /// option(seed) /// label("Random-number seed") TEXT tx_note _lft _ls _iwd ., /// label("These verbs change the view's plan only; materialise the result with parqit collect or parqit save.") TEXT tx_context _lft 310 470 ., label("Current view: refresh to check") BUTTON bu_context _rj80 @ 80 ., label("Refresh") onpush(program main_context) END PROGRAM main_context BEGIN put "parqit _dlgcontext " put dlgname stata hidden queue clear END PROGRAM main_mode BEGIN call main.tx_if.disable call main.ex_if.disable call main.tx_from.disable call main.ed_from.disable call main.tx_to.disable call main.ed_to.disable call main.tx_fl.disable call main.tx_amount.disable call main.ed_amount.disable call main.ck_count.disable call main.tx_seed.disable call main.ed_seed.disable if main.rb_keepif | main.rb_dropif { call main.tx_if.enable call main.ex_if.enable } if main.rb_keepin | main.rb_dropin { call main.tx_from.enable call main.ed_from.enable call main.tx_to.enable call main.ed_to.enable call main.tx_fl.enable } if main.rb_sample { call main.tx_amount.enable call main.ed_amount.enable call main.ck_count.enable call main.tx_seed.enable call main.ed_seed.enable } END PROGRAM main_ds BEGIN put "parqit ds" stata END PROGRAM command BEGIN if main.rb_keepif { require main.ex_if put "parqit keep if " main.ex_if } if main.rb_dropif { require main.ex_if put "parqit drop if " main.ex_if } if main.rb_keepin { require main.ed_from require main.ed_to put "parqit keep in " main.ed_from "/" main.ed_to } if main.rb_dropin { require main.ed_from require main.ed_to put "parqit drop in " main.ed_from "/" main.ed_to } if main.rb_sample { require main.ed_amount put "parqit sample " main.ed_amount beginoptions option main.ck_count optionarg main.ed_seed endoptions } END