Announcement

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

  • trying to reproduce HTML character reference issues

    Copied from a code block and pasted.
    Code:
        qui drop if (idcase == `c') & (seqnum > `ControlsPerCase')
    Copied from a preview of the block above and pasted wiithout changing to plain text before the first actual post
    Code:
         qui drop if (idcase == `c') & (seqnum > `ControlsPerCase')
    Same copy pasted as plain text
    Code:
        qui drop if (idcase == `c') & (seqnum > `ControlsPerCase')
    First post now.

    Editing now.
    Copied from the first block above in the posted version and pasted here without changing while editing.
    Code:
         qui drop if (idcase == `c') & (seqnum > `ControlsPerCase')
    Save edit now.

    No luck reproducing problem.
    Last edited by William Lisowski; 02 Jul 2019, 17:39.

  • #2
    Code:
    Code:
    // Matched case-control sampling using incidence density sampling, with no replacement.
    //
    // Create example files of cases and controls to work with.
    // Example conditions
    clear
    set seed 33245
    local matchvars = "x y z"
    local maxtime = 50
    local pcase = 0.05 // proportion of case events among all observations
    local ControlsPerCase = 3
    set obs 100000 // total number of persons, cases and potential controls
    //
    //
    gen int id = _n
    gen int evtime = ceil(runiform() * `maxtime')  // time of disease event
    replace evtime = . if runiform() > `pcase' // Many persons never have the disease event
    // Create variables beside event time on which cases and controls would be matched.
    foreach v of local matchvars {
      gen `v'  = ceil(3*runiform())   // 3 value for each match variable
    }
    // End of preparing example data
    //  *********************************************
    //
    // Within this file of cases and controls, everyone is a potential control to start with,
    // so save everyone in this file as a source of controls.
    compress // important to save memory
    tempfile filecase filectl
    rename id idctl
    rename evtime evtimectl
    // randomize the order of the controls
    gen rand = runiform()
    sort rand, stable
    drop rand
    save `filectl'      // file of controls
    rename idctl idcase
    rename evtimectl evtimecase
    //
    //
    // Strip the current file down to just the cases.
    drop if missing(evtimecase)
    qui count
    di r(N) " event cases in file"
    //
    // Pair up each case with each of the potential controls that match on the matching variables.
    // We will worry about time of event, risk set, etc. later.
    joinby `matchvars' using `filectl'
    //
    //
    // Drop impossible pairs
    drop if (idcase == idctl)          // self pairs
    drop if (evtimecase >= evtimectl)  // control member is not in risk set
    //
    // A few details before we start incidence sampling
    gen rand = runiform()
    sort idcase rand, stable // randomize the order of the cc pairs
    drop rand evtime* x y z // don't need these anymore
    by idcase: gen byte first = (_n ==1)  // just to count cases
    qui count if first ==1
    di r(N) " event cases that have a potential match after considering event time"
    //
    //
    // Keep the desired number of controls for each case.  For each case,
    // remove her/his controls from all other case-control pairs so
    // as to give sampling w/o replacement.
    // I use a loop here over all case-control pairs , generally not Stata-ish,
    // but it seems like a good approach here.
    by idcase: gen int seqnum = _n   // sequence number of the c-c pair for each case case
    qui levelsof idcase, local(caselist)  // a list of all the cases
    gen byte casedone = 0 // to mark each case as we process it.
    foreach c of local caselist {
        // Keep desired number of c-c pairs for this case
        qui drop if (idcase == `c') & (seqnum > `ControlsPerCase')
        qui replace casedone = 1 if (idcase == `c')
        //
        // Make a list of the controls just used. I used a clumsy approach with preserve/restore.
        preserve
           qui keep if (idcase == `c')   // current case/control pairs
           local used ""  // will hold the list of controls just used
           forval i = 1/`ControlsPerCase' {
             local used = "`used' " + string(idctl[`i'])
           }   
        restore
        //
        //  Drop all remaining unexamined pairs that involve the controls just used
        local used = subinstr(ltrim("`used'"), " " , ",", .)
        qui drop if (casedone == 0 ) & inlist(idctl, `used')
    }
    // Report on number of cases and controls matched.
    by idcase: gen NCtl = _N
    tab NCtl if first, missing

    Comment


    • #3
      Code:
      < > <<<< >>>>>>
      <html>
      the forum software definitely messes with the code, the above was typed as HTML all in caps!

      Comment


      • #4
        Code:
        <html>
        Indeed! And preview showed it in all caps before I hit post.

        Thanks, I feel a little less paranoid now.

        Comment

        Working...
        X