⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ztspli_5.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
    if "`display'" != "" { di in gr "numlist: " in ye "`nlist'" }
    global S_1 "`nlist'"
    global S_2 "`nnl'"        
end

program define sortlist

    if "`*'" == "" { 
        global S_1
        global S_2    
        exit 
    }

    local key "`1'"   /* list to be sorted */
    local v   "`2'"   /* list to-be-permuted just like key */       
    if "`v'" == "," {
        local v 
        mac shift 1
    }
    else mac shift 2

    local options "Ascending Descending DIsplay"
    parse "`*'"

    local k : word count `key'
    if "`v'" != "" {    
        local nv : word count `v'
        if `nv' != `k' { exit 198 }
        * simulate array access
        local i 1
        while `i' <= `k' {
            local v`i'   : word `i' of `v'
            local key`i' : word `i' of `key'
            confirm number `key`i''
            local i = `i'+1
        }
    }
    else {
        * simulate array access with v = 1,2,3,4...
        local i 1
        while `i' <= `k' {
            local key`i' : word `i' of `key'
            confirm number `key`i''
            local v`i' `i' 
            local v "`v'`v`i'' "
            local i = `i'+1
        }
    }

  * insert-sort sorting order direct
        
    if "`descend'" != "" & "`ascendi'" == "" { 
          local direct ">" 
    }
    else  local direct "<"

    local i 1
    while `i' <= `k' {
        * search mj (index of maximum/minimum of key) among i..k
        local j `i'            
        local mj `j'
        local mkey `key`j''
        while `j' <= `k' {
           if `key`j''  `direct'  `mkey' {
               local mj   `j'
               local mkey `key`j'' 
           }
           local j = `j'+1
        }

        * swap i and mj
        if `i' != `mj' {
           local tmp     `key`i''  
           local key`i'  `key`mj''
           local key`mj' `tmp'

           local tmp     `v`i''  
           local v`i'    `v`mj''
           local v`mj'   `tmp'
        }
        local i = `i'+1
    }                 
    
    * re-assemble -key- into S_1 and -v- into S_2
    global S_1
    global S_2    
    local i 1
    while `i' <= `k' {
        global S_1 "$S_1`key`i'' "        
        global S_2 "$S_2`v`i'' "        
        local i = `i'+1
    }                 

    if "`display'" != "" {    
        di in gr "keys   " in ye "`key'" in gr " -> " in ye "$S_1"
        di in gr "values " in ye "`v'"   in gr " -> " in ye "$S_2"
    }    
end

program define parsoptp
        
        if "`*'" == "" { 
                global S_1
                global S_2
                global S_3
                global S_4
                global S_5
                exit 
        }
                
        local optname "`1'"  /* name of option */
        mac shift
        
        * replaces spaces by a char (space), to put spaces back in later
        if "$S_PCHAR" == "" {
                local space "@"
        }
        else    local space "$S_PCHAR"                
        while "`1'" != "" {
                local input "`input'`1'`space'"
                mac shift
        }
        
        local H 0            /* level of nesting (#opened parenthesis/brackets) */
        local Mode0   "None" /* None, p(arentheis), b(racket) */        
        local OptFnd  0      /* set to 1 if optname found */
        local ProcOpt 0      /* set to 1 during processing options */
        local ProcArg 0      /* set to 1 during processing args of optname */
        local NonOpt         /* set to input that does not belong to options */
        local Arg            /* set to argument of optname */
        local RestOpt        /* set to options other than optname */
       
        parse "`input'", p("`space'()[],")
        while "`1'" != "" {
                if "`1'" == "," & `H' == 0 {
                        * toggle Options <--> NonOptions
                        local ProcOpt = 1-`ProcOpt'
                }
                else if `ProcOpt'==1 & "`1'" == "`optname'" & `H' == 0 {
                        if `OptFnd' > 0 {
                                di in re "option `optname' occurs more than once"
                                exit 198
                        }                                
                        local OptFnd 1               /* option found */ 
                        if "`2'" == "(" {            
                                mac shift            /* skip option name & "(" */
                               *akward but necessary if option text exceeds 80 chars
                               *so we can't simply take off enclosing () later on
                                local H = `H'+1      /* push "parenthesis" */
                                local Mode`H' "p"
                                local ProcArg 1      /* options has argument */
                        }
                }
                else {
                        if "`1'" == "(" {
                                local H = `H'+1      /* push "parenthesis" */
                                local Mode`H' "p"
                        }
                        else if "`1'" == "[" {
                                local H = `H'+1      /* push "bracket" */
                                local Mode`H' "b"
                        }
                        else if "`1'" == ")" {
                                if "`Mode`H''" ~= "p" { ErrNest }
                                local H = `H'-1      /* pop previous mode */
                        }
                        else if "`1'" == "]" {
                                if "`Mode`H''" ~= "b" { ErrNest }
                                local H = `H'-1      /* pop previous mode */
                        }
                        else if "`1'" == "`space'" {
                                local 1 " "          /* restore space */
                        }
                                                        
                        * store text in -Arg-, -RestOpt-, or -NonOpt-
                        if `ProcArg' == 1 {
                                if `H' > 0 {
                                        local Arg  "`Arg'`1'" 
                                }
                        }                        
                        else if `ProcOpt' == 1 {
                                local RestOpt "`RestOpt'`1'"
                        }
                        else    local NonOpt  "`NonOpt'`1'"
                                                

                        * end-of-arg reached
                        if `H' == 0 { 
                                local ProcArg 0 
                        }                                
                }
                mac shift
        }                
        if `H' ~= 0 { 
                di in re "too few ')' or ']'" 
                exit 132
        }
        
      * save results
        
        if `OptFnd' > 0 {
                global S_1 "`optname'"
        }                
        else    global S_1
        global S_2 "`Arg'"
        if "`RestOpt'" ~= "" { local c ", " }
        global S_3 "`NonOpt'`c'`RestOpt'"
        global S_4 "`NonOpt'"
        global S_5 "`RestOpt'"
        * di "$S_1/$S_2/$S_3"
end

program define ErrNest
        di in re "too many or mismatching ')' or ']'"
        exit 132
end 
         

program define _st_aux

        local options "noSHow"
        parse "`*'"

        * interface to stset

        local id : char _dta[st_id]
        local t  : char _dta[st_t]
        local t0 : char _dta[st_t0]
        local d  : char _dta[st_d]
        local w  : char _dta[st_w]

        if "`id'" == "" {
                MakeVar "case identification (id)" id caseid CaseID st_id st_ID
                local id "$S_1"
                gen int `id' = _n
                label var `id' "st: case identifier"
                char _dta[st_id] `id'
                local newid 1
        }

        if "`d'" == "" {
                MakeVar "failure variable (died)" died st_d st_died failure status
                local d "$S_1"                
                gen byte `d' = 1
                label var `d' "st: failure/censor identifier"
                char _dta[st_d] `d'
                local newd 1
        }

        if "`t0'" == "" {
                MakeVar "entry times (t0)" t0 etime st_t0 
                local t0 "$S_1"
                gen byte `t0' = 0
                label var `t0' "st: entry times"
                char _dta[st_t0] `t0'
                local newt0 1
        }
        
      * if new variables are generated, display definitions
       
        if "`show'" == "" & "`newid'`newd'`newt0'" ~= "" { 

                di _n in gr "st key variables were created" _n
            
                if "$S_FN" ~= "" {
                        di in gr _col(4) "data set name:  " in ye "$S_FN"
                }
            
                di _col(15) in gr "id:  " in ye _c
                if "`newid'" ~= "" {
                        di "`id'" _col(18) in gr "defined to _n: each record a unique subject"
                }
                else    di "`id'" 
                
                di _col(7) in gr "entry time:  " in ye _c 
                if "`newt0'" ~= "" {
                        di in ye "`t0'" _col(18) in gr "defined to 0, meaning all entered at time 0"
                }
                else    di "`t0'"
            
                di _col(8) in gr "exit time:  " in ye "`t'"

                di _col(3) in gr "failure/censor:  " in ye _c
                if "`newd'" ~= "" {
                        di "`d'" _col(18) in gr "defined to 1, meaning all failed"
                }
                else    di "`d'"
            
                if "`w'" ~= "" {
                        di in gr _col(11) "weight:  " in ye "`w'"
                }
        }
        else {
                zt_sho_5 `show'
        }            
end

* copied from stset (StataCorp)
program define MakeVar /* opname <potential-name-list> */
        local option "`1'"
        mac shift
        local list "`*'"
        while "`1'" ~= "" {
                capture confirm new var `1'
                if _rc == 0 {
                        global S_1 "`1'"
                        exit
                }
                mac shift
        }
        di in red "could not find variable name for `option'"
        di in red "      tried:  `list'"
        di in red "      specify `option' explicitly"
        exit 110
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -