Hi everyone,

I have cross-sectional loan data from 2007-2010. For each year I have at least 100 observations (loans). Now I would like to count all the loans that have the loan status "default" in year 2007.

Code:
count if loan_status=="Default" & Year==2007
0

The output is zero, but I know that there must be more than 40.
Variable "Year" has the format %tdCCYY. Does anyone know what is wrong with my code?

I found a post in the forum for someone with a similar situation:

bysort year loan_status : gen count = _n == 1
by year : replace count = sum(count)
by year: replace count = _N
tabdisp year, cell(count)

However, I do not know if 1) this code fits my problem and 2)how to implement the if-condition (if loan_status==Default). I would be happy if anyone could help me out. Thanks a lot in advance!