Announcement

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

  • Reshape wide with multiple j strings

    Hi,

    How can I reshape my variables with multiple j strings? I have tried something like this:

    reshape wide var1 var2 gap boundL boundH, i(variable eventtime) j(gender sector, string)

    where I want to get the following system of variables out for "gap":

    gapmenprivate
    gapwomenprivate
    gapmenpublic
    gapwomenpublic

    (Here gender is either "men" or "women" and sector is either "private" or "public".

    Thanks in advance.

  • #2
    We (or at least I) need a data example please.

    Comment


    • #3
      My data looks like this (an example)
      Gap variable gender sector
      324.94 wage men private
      350.84 wage men public
      430.23 wage women private
      433.43 wage women public
      9532.48 income men private
      4830.43 income men public
      4820.43 income women private
      4830.43 income women public
      ... ... ... ...
      Many thanks.

      Comment


      • #4
        The thing is, that I want to uniquely identify my observations with gender and sector (per variable). I thought I could call them

        gapmenprivate
        gapwomenprivate
        gapmenpublic
        gapwomenpublic

        for each variable: wage and income.

        Hope it makes sence.

        Comment


        • #5
          #2 doesn't seem to match the syntax in #1. but it is what you give us.

          #2 is helpful, but not a data example as we request here (FAQ Advice #12). Whether you have string variables or numeric variables with value labels is ambigous, in particular.

          I don't understand quite what you're imagining, but this is what I would do


          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float gap str6 variable str5 gender str7 sector
           324.94 "wage"   "men"   "private"
           350.84 "wage"   "men"   "public"
           430.23 "wage"   "women" "private"
           433.43 "wage"   "women" "public"
          9532.48 "income" "men"   "private"
          4830.43 "income" "men"   "public"
          4820.43 "income" "women" "private"
          4830.43 "income" "women" "public"
          end
          
          . reshape wide gap, i(gender sector) j(variable) string
          (j = income wage)
          
          Data                               Long   ->   Wide
          -----------------------------------------------------------------------------
          Number of observations                8   ->   4          
          Number of variables                   4   ->   4          
          j variable (2 values)          variable   ->   (dropped)
          xij variables:
                                              gap   ->   gapincome gapwage
          -----------------------------------------------------------------------------
          
          . rename (gap*) (*gap)
          
          . l
          
               +---------------------------------------+
               | gender    sector   income~p   wagegap |
               |---------------------------------------|
            1. |    men   private    9532.48    324.94 |
            2. |    men    public    4830.43    350.84 |
            3. |  women   private    4820.43    430.23 |
            4. |  women    public    4830.43    433.43 |
               +---------------------------------------+
          Last edited by Nick Cox; 10 Nov 2021, 10:18.

          Comment

          Working...
          X