Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Extracting substrings from variable and combining variables.


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Extracting substrings from variable and combining variables.
Date   Fri, 1 Jun 2012 18:31:55 +0100

There is a tutorial on -foreach- at 

SJ-2-2  pr0005  . . . . . .  Speaking Stata:  How to face lists with fortitude
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q2/02   SJ 2(2):202--222                                 (no commands)
        demonstrates the usefulness of for, foreach, forvalues, and
        local macros for interactive (non programming) tasks

. search foreach 

will get you to a clickable link. 

If you want a composite variable, you can use -egen- and then modify the resulting variable with -replace- to get what you want. Or you can write your own code to get what you want. I don't know exactly what you want, so that rules out further suggestions from me for the time being. You would get better help by giving examples of what the variables you want would look like. 

Nick 
[email protected] 

Amal Khanolkar

Thanks for the input and code:

I didn't really understand what the code does (''for each etc...'')
But it does pluck out the those that have the 3 diagnoses of interest and creates 3 separate variables as follows:

tab  has637

     has637 |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |  2,969,464       99.26       99.26
          1 |     21,992        0.74      100.00
------------+-----------------------------------
      Total |  2,991,456      100.00

. tab  has642

     has642 |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |  2,948,590       98.57       98.57
          1 |     42,866        1.43      100.00
------------+-----------------------------------
      Total |  2,991,456      100.00

. tab  hasO1

      hasO1 |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |  2,968,084       99.22       99.22
          1 |     23,372        0.78      100.00
------------+-----------------------------------
      Total |  2,991,456      100.00

- The above also gives a lower number and skips those recorded as duplicates.


- I think using the replace command to restructure preght is probably easier: however you meant I do it before that is using the original 12 variables and skipping egen all together?


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index