Announcement

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

  • Transforming data

    Hello
    Greetings

    I have one dataset , named input file, attached, from which i want to make output file, also attached, through commands or do file.

    For the understanding purpose , i have done it manually and attached both input and output file.
    How can i get output file based structure, based on input data.

    Many Thanks
    .
    Attached Files

  • #2
    Code:
    // InputStataFile.dta presented using dataex as requested by Statalist FAQ
    
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte month str7 sitename byte cumulative_count
    1 "AIIMS"    5
    2 "AIIMS"   35
    3 "AIIMS"   45
    5 "AIIMS"   50
    4 "IGMC"     2
    5 "IGMC"     6
    2 "SCTIMST"  2
    3 "SCTIMST"  6
    4 "SCTIMST"  9
    5 "SCTIMST" 11
    3 "JIPMER"   1
    4 "JIPMER"  14
    5 "JIPMER"  39
    2 "SJIC"     1
    3 "SJIC"    11
    4 "SJIC"    15
    5 "SJIC"    22
    2 "SGPGI"    4
    3 "SGPGI"   17
    4 "SGPGI"   20
    5 "SGPGI"   22
    3 "KGMC"    14
    4 "KGMC"    20
    5 "KGMC"    27
    2 "SRMC"     5
    3 "SRMC"     8
    4 "SRMC"    11
    5 "SRMC"    12
    2 "GBPH"     7
    3 "GBPH"    15
    4 "GBPH"    24
    5 "GBPH"    30
    end
    
    rename cumulative_count cc_
    reshape wide cc_, i(month) j(sitename) string
    rename cc_* *
    list, clean
    Code:
    . rename cumulative_count cc_
    
    . reshape wide cc_, i(month) j(sitename) string
    (j = AIIMS GBPH IGMC JIPMER KGMC SCTIMST SGPGI SJIC SRMC)
    
    Data                               Long   ->   Wide
    -----------------------------------------------------------------------------
    Number of observations               32   ->   5           
    Number of variables                   3   ->   10          
    j variable (9 values)          sitename   ->   (dropped)
    xij variables:
                                        cc_   ->   cc_AIIMS cc_GBPH ... cc_SRMC
    -----------------------------------------------------------------------------
    
    . rename cc_* *
    
    . list, clean
    
           month   AIIMS   GBPH   IGMC   JIPMER   KGMC   SCTIMST   SGPGI   SJIC   SRMC  
      1.       1       5      .      .        .      .         .       .      .      .  
      2.       2      35      7      .        .      .         2       4      1      5  
      3.       3      45     15      .        1     14         6      17     11      8  
      4.       4       .     24      2       14     20         9      20     15     11  
      5.       5      50     30      6       39     27        11      22     22     12  
    
    .
    Please note that I presented your InputStataFile.dta using the dataex command, rather than reading it from the downloaded file, because that is the preferred method of presenting example data. You of course can apply the recommended code directly to your Stata dataset, but many members are reluctant to download files from unknown sources. And in any event, those interested in this topic might be reading this on a system that does not have Stata installed, so they can learn nothing from this answer.

    Please take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It is particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

    The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

    Comment


    • #3
      Many Thanks for your help.Indeed it is good idea to post the question in question area , instead of attachments.

      Comment

      Working...
      X