Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is or where is parse_collapse_clist?

    Dear Stata users,

    I use -retainlbl- command worte by Mead Over. When I try to run it on collapse, it failed. And the error suggests that command parse_collapse_clist is unrecognized. I searched in my computer and web, nothing found. The helpfile of -retainlbl- said that the it is UNDER CONSTRUCTION (I have noticed that the grammer in retainlbl's official example is wrongly specified). But I want to know what is parse_collapse_clist? (Stata 16 in use.) Thank you.

    Code:
    package retainlbl from http://digital.cgdev.org/doc/stata/MO/Misc
    -----------------------------------------------------------------------------------------------------------------
    
    TITLE
          `retainlbl'. Restores variable labels after, e.g., collapse
    
    DESCRIPTION/AUTHOR(S)
          Some STATA operations, such as the collapse and reshapecommands,
          alter or destroy variable labels during execution.
          retainlbl stores the labels of a list of variables in macros
          and then restores them after execution of the label-destroying command.
          
          by Mead Over, Center for Global Development
          http://www.cgdev.org/expert/mead-over
          
          Requires Stata Version 14.2 or later
          
          Version 3.3 23Feb2025
          
          Distribution-Date: 20250223
    
    INSTALLATION FILES                                  (click here to install)
          retainlbl.ado
          retainlbl_reshape_sub.ado
          retainlbl.sthlp
    
    ANCILLARY FILES                                     (click here to get)
          retainlbl_example.do
    Code:
    . webuse college, clear
    
    . list
    
    
    gpa   hour   year   number 
    -
    1.  3.2     30      1        3 
    2.  3.5     34      1        2 
    3.  2.8     28      1        9 
    4.  2.1     30      1        4 
    5.  3.8     29      2        3 
    -
    6.  2.5     30      2        4 
    7.  2.9     35      2        5 
    8.  3.7     30      3        4 
    9.  2.2     35      3        2 
    10.  3.3     33      3        3 
    -
    11.  3.4     32      4        5 
    12.  2.9     31      4        2 
    
    
    . describe
    
    Contains data from https://www.stata-press.com/data/r16/college.dta
    obs:            12                          
    vars:             4                          3 Jan 2018 12:05
                            
    storage   display    value
    variable name   type    format     label      variable label
                            
    gpa             float   %9.0g                 gpa for this year
    hour            int     %9.0g                 Total academic hours
    year            int     %9.0g                 1 = freshman, 2 = sophomore,    3    =    junior,    4    =
    senior
    number          int     %9.0g                 number of students
                            
    Sorted by: year
    
    . retainlbl gpa hour year, store
    Beginning with version 3.0, syntax is:
    retainlbl (collapsereshape) [varlist] , (storerestore) [options]
    Here, instead of -collapse- or -reshape-, the subcommand is -gpa-.
    r(198);
    
    . retainlbl collapse gpa hour year, store
    command parse_collapse_clist is unrecognized
    r(199);
    
    . which retainlbl
    c:\ado\plus\r\retainlbl.ado
    *!  version 3.3 23Feb2025   by Mead Over   UNDER CONSTRUCTION

  • #2
    I suggest that you ask Mead Over, the program author.

    Comment


    • #3
      Yes, But 15. May I ask for private replies? Please do not request private replies unless you are posting about employment or consultancy opportunities. Statalist is based on replying to the forum, not personally to the poster, with the ideal that postings are of interest to many.

      Comment


      • #4
        parse_collapse_clist is called by retainlbl but is missing from its installation package. As Nick suggested, please contact Mead Over so he can provide the missing helper and update the package.

        In the meantime, you can use a simple workaround: save the variable labels before collapse and restore them afterward. This approach does not require the missing helper program and is also described in the official Stata FAQ https://www.stata.com/support/faqs/data-management/keeping-same-variable-with-collapse.

        Please run the entire code block at once to preserve the local macros. The first example applies when variable names remain unchanged after collapse. The second example renames the variables to mean_gpa and sd_gpa and assigns appropriate labels for the mean and standard deviation.

        Code:
        * Temporary replacement for the variable-label function of retainlbl collapse.
        * Run the whole do-file. No additional ado files are required.
        * The data in memory are preserved and restored after the examples.
        * An optional first argument specifies the parse_collapse folder.
        version 16.0
        args project_dir
        if `"`project_dir'"' == "" {
            local project_dir "/replace_with_your_working_directory"
        }
        confirm file `"`project_dir'/evidence_20261011/college.dta"'
        
        preserve
        tempname demo_log
        log using `"`project_dir'/temporary_workaround_results.log"', text replace name(`demo_log')
        display "Stata version: " c(stata_version)
        
        * Example 1: retain the original variable names and labels.
        use `"`project_dir'/evidence_20261011/college.dta"', clear
        
        foreach v of varlist gpa hour year {
            local lbl_`v' : variable label `v'
        }
        
        collapse (mean) gpa hour [fw=number], by(year)
        
        foreach v of varlist gpa hour year {
            label variable `v' `"`lbl_`v''"'
        }
        
        assert _N == 4
        isid year
        assert abs(gpa - 50.2/18) < 1e-6 if year == 1
        assert abs(gpa - 35.9/12) < 1e-6 if year == 2
        assert abs(gpa - 29.1/9) < 1e-6 if year == 3
        assert abs(gpa - 22.8/7) < 1e-6 if year == 4
        foreach v of varlist gpa hour year {
            local actual : variable label `v'
            assert `"`actual'"' == `"`lbl_`v''"'
        }
        describe
        list, noobs
        display "PASS 1: weighted means and original variable labels"
        
        * Example 2: new variable names, with two statistics for gpa.
        use `"`project_dir'/evidence_20261011/college.dta"', clear
        local lbl_gpa  : variable label gpa
        local lbl_hour : variable label hour
        local lbl_year : variable label year
        
        * Reference values from the original data, used only for verification.
        forvalues y = 1/4 {
            quietly summarize gpa if year == `y' [fw=number]
            local ref_mean_gpa_`y' = r(mean)
            local ref_sd_gpa_`y' = r(sd)
            quietly summarize hour if year == `y' [fw=number], meanonly
            local ref_mean_hour_`y' = r(mean)
        }
        
        collapse (mean) mean_gpa=gpa mean_hour=hour ///
                 (sd) sd_gpa=gpa [fw=number], by(year)
        
        label variable mean_gpa  `"Mean: `lbl_gpa'"'
        label variable mean_hour `"Mean: `lbl_hour'"'
        label variable sd_gpa    `"SD: `lbl_gpa'"'
        
        assert _N == 4
        isid year
        forvalues y = 1/4 {
            assert reldif(mean_gpa, `ref_mean_gpa_`y'') < 1e-6 if year == `y'
            assert reldif(mean_hour, `ref_mean_hour_`y'') < 1e-6 if year == `y'
            assert reldif(sd_gpa, `ref_sd_gpa_`y'') < 1e-6 if year == `y'
        }
        local actual : variable label mean_gpa
        assert `"`actual'"' == "Mean: gpa for this year"
        local actual : variable label mean_hour
        assert `"`actual'"' == "Mean: Total academic hours"
        local actual : variable label sd_gpa
        assert `"`actual'"' == "SD: gpa for this year"
        local actual : variable label year
        assert `"`actual'"' == `"`lbl_year'"'
        describe
        list, noobs
        display "PASS 2: renamed variables, multiple statistics, and descriptive labels"
        
        display "ALL EXAMPLES PASSED"
        log close `demo_log'
        restore
        Last edited by Choonjoo Lee; Yesterday, 04:52.

        Comment


        • #5
          Mead Over is a member here and may or may not reply on the list. The point of my post was to suggest that if he doesn't reply on the list, then you have the option of emailing him privately. (It has been some months since he was last here.)

          Any way, this is the third ping....
          Last edited by Nick Cox; Yesterday, 11:02.

          Comment


          • #6
            Yes, Statalist has (had) some network failure today (or yesterday). Many times cannot be opened.

            Comment

            Working...
            X