Announcement

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

  • creating a subsample based on a dummy variable

    I´m using Stata 14 with Windows 10 OS - 64bits.

    I´m working with a panel data from 1995 to 2017.

    I want to separate my data on two sub samples depending whether or not a firm have access to a specific line of credit. I created a dummy variable equal one if a given firm have used such line of credit in a given year and zero otherwise.
    Now I want to separate my data as follows: a sub sample if the firm have never used the line of credit (so the dummy is always zero) and a different sub sample if the firm had used the credit line at least once (dummy equals one at least once).

    Is that a easy way to do this?

  • #2

    FAQ 12.1 : We can understand your dataset only to the extent that you explain it clearly. The best way to explain it is to show an example. The community-contributed command dataex makes it easy to give simple example datasets in postings. It was written to support Statalist and its use is strongly recommended. Usually a copy of 20 or so observations from your dataset is enough to show your problem. See help dataex for details.

    Code:
    by firm_id, sort: egen sum_creditline= total(creditline_Dummy)
    gen subsample=. 
    replace subsample=0 if sum_creditline==0
    replace subsample=1 if sum_creditline!=0 & sum_creditline!=. 

    Comment


    • #3
      Yes. I know. You right. I apologize.

      Nevertheless, the code worked perfectly. Thanks a lot.

      Comment

      Working...
      X