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: generating variable with condition on same variable


From   Ronnie Babigumira <[email protected]>
To   [email protected]
Subject   Re: st: generating variable with condition on same variable
Date   Fri, 27 Dec 2013 09:56:03 +0100

Does this work?

clear
input  hhid   pump
       7      3
       8      3
       8      4
       9      3
       9      4
      10      3
      10      .
      11      1
end

label define pmpl 1"Tube" 3"Diesel" 4"Electric"
la val pump pmpl

* How many pumps
bys hhid : egen n_allpumps = count(pump)
bys hhid : egen n_dieselpumps = total(pump == 3)
bys hhid : egen n_otherpumps = total(!inlist(pump,3,.))
list

    hhid       pump   n_allpumps   n_dieselpumps   n_otherpumps
       7     Diesel            1               1              0
       8     Diesel            2               1              1
       8   Electric            2               1              1
       9     Diesel            2               1              1
       9   Electric            2               1              1
      10     Diesel            1               1              0
      10          .            1               1              0
      11       Tube            1               0              1

On Fri, Dec 27, 2013 at 5:22 AM, Prakash Singh <[email protected]> wrote:
> Hello,
> I need help in generating a variable based on following condition
>
> I have one data file at household level where the variable itemcode
> indicates type of pump household own. I want to see how may of the
> households who have diesel pump also own any other type of pump. For
> example a new variable can be created where if the farm (diesel pump
> owner) have one electric pump or one tube well.
>
>
> Many thanks in advance
>
> Regards
> Prakash
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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