Announcement

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

  • Problem on how to aggregate results for dummy variables

    Hi everyone
    I have a set of varibales which are expressed as dummy and i would like to study them. I've encountered this image which is basically showing people who have either stocks or mutual funds or both of them in their portfolio, avoiding to overcount persons who have both stocks and mutual funds (basically treating them just as one person and not as two: in plain vanilla, if only stocks 1, only mutual fund 1 and both 1). Now i'm unable to replicate a function or a code that would allow me to count in this way. Is there anyone willing to help me? I need also to do the same reasoning for even more variable, but now i'm just with these two
    Thank You very much

  • #2
    It is somewhere between difficult and impossible to help with a problem like this without seeing an example of your dataset. Please use the -dataex- command and post back with an example.

    If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Alessandro:
      welcome to this forum.
      I do share Clyde's advidce aboutcprofiding the list with an excerpt/example of your dataset via -dataex.
      Hence, what follows should be considered as a temptative answer, based on my personal guess-work:
      Code:
      . set obs 3
      number of observations (_N) was 0, now 3
      
      . g id=_n
      
      . g Mutual_Fund=0 in 1/2
      
      
      . replace Mutual_Fund=1 if Mutual_Fund==.
      
      
      . g Stocks=0 in 2
      
      
      . replace Stocks=1 if Stocks==.
      
      
      . egen wanted=group(Mutual_Fund Stocks)
      
      . list
      
           +---------------------------------+
           | id   Mutual~d   Stocks   wanted |
           |---------------------------------|
        1. |  1          0        1        2 |
        2. |  2          0        0        1 |
        3. |  3          1        1        3 |
           +---------------------------------+
      
      . label define wanted 1 "NeitherMutualNorStocks" 2 "NoMutualYesStocks" 3"YesMutualYesStock" 4 "YesMutualNoStocks"
      
      . label val wanted wanted
      
      . list
      
           +-------------------------------------------------+
           | id   Mutual~d   Stocks                   wanted |
           |-------------------------------------------------|
        1. |  1          0        1        NoMutualYesStocks |
        2. |  2          0        0   NeitherMutualNorStocks |
        3. |  3          1        1        YesMutualYesStock |
           +-------------------------------------------------+
      
      .
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Clyde Schechter Carlo Lazzaro Thank You so much. i still have to figure it out how to be comprehended properly.

        input byte(pos_d5 pos_d6 pos_d7 pos_f) where 1st refer to balanced etf (bond +stocks), 2nd to pure stock etf , 3rd to stocks in other currencies and 4th to equity mutual fund
        0 0 0 1
        0 0 0 0
        0 1 0 0
        0 0 0 0
        0 0 0 0
        0 1 1 0 for example in this line there are two 1, it means that this particular individual has both pure stocks etf and stocks in other currencies, but i still want to count it as one and not double count it (sum them up in the category of equity mutual funds)
        0 0 0 1
        1 0 0 0
        0 0 0 0
        0 1 0 0
        0 0 1 0
        0 0 0 0
        0 0 0 0
        0 0 0 0
        0 0 0 0
        end
        [/CODE]
        ------------------ copy up to and including the previous line ------------------

        Listed 100 (i've cut a piece) out of 32235 observations
        Use the count() option to list more

        Comment


        • #5
          Alessandro:
          elaborating a bit on my previous toy-example:
          Code:
          set obs 3
          g id=_n
          g Mutual_Fund=0 in 1/2
          replace Mutual_Fund=1 if Mutual_Fund==.
          g Stocks=0 in 2
          replace Stocks=1 if Stocks==.
          egen wanted=rowmax( Mutual_Fund Stocks )
          list
          
               +---------------------------------+
               | id   Mutual~d   Stocks   wanted |
               |---------------------------------|
            1. |  1          0        1        1 |
            2. |  2          0        0        0 |
            3. |  3          1        1        1 |
               +---------------------------------+
          
          .
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            Carlo Lazzaro Thank You. You have been extremely kind

            Comment

            Working...
            X