user16626: May I know how to find in all grandmaster games, what the percentage of each of the following is?

Kingside castling
Queenside castling
Never castled by the end of the game but still has the right to castle
Lost the right to castle

Note When one side has castled more than once in a game, only the first castle counts.

user7297: Just googling for "castling statistics" already yields a few results; even though the analysis is done on a different set of games than 'all grandmaster games', it gives a rough indication.

50 world class players
2 million games in the MillionBase database

Kingside castling is done by 80-81% of the players, and queen side castling by 8-9%. I estimate that Never castled by the end of the game but still has the right to castle is negligible (less than 0.1%, since it requires a very short game). So that leaves about 11% for the final group Lost the right to castle.

user12951: If you are prepared to use standard Linux command-line tools like wc and grep then I think my free PGN processor, pgn-extract, will do much of the pre-processing necessary to count games in each category. Below is a basic bash script I put together as a proof of concept. It assumes your file of games is called inputfile.pgn - adjust as necessary, or pass it in as a command-line argument:
#!/bin/bash
# Output stats on castling.
src=inputfile.pgn
# Pre-process the games to allow textual analysis.
pgn-extract -C -V -N --notags --nochecks --linelength 10000 -s -o stripped.pgn ${src}
# Castling by white: detect a preceding move number.
grep '\. O-O ' stripped.pgn > Wkingside.pgn
grep '\. O-O-O ' stripped.pgn > Wqueenside.pgn
# Castling by black: detect no preceding move number.
grep '[^.] O-O ' stripped.pgn > Bkingside.pgn
grep '[^.] O-O-O ' stripped.pgn > Bqueenside.pgn
# Find games in which no castling occurred.
grep -v ' O-O ' stripped.pgn | grep -v ' O-O-O ' | grep -v '^$' > nocastle.pgn

# Output the FEN of the final position to include castling rights and
# look for the presence of rights.
pgn-extract -C -V -N --notags --nomovenumbers --linelength 10000 -s nocastle.pgn --dropply -1 -F | grep ' [wb] [KkQq]' > rights.txt

# Output the results - assumes valid Result tags in the source.
echo 'Number of games: ' `grep '^\[Result ' ${src} | wc -l`
echo 'W Kingside: ' `cat Wkingside.pgn | wc -l`
echo 'W Queenside: ' `cat Wqueenside.pgn | wc -l`
echo 'B Kingside: ' `cat Bkingside.pgn | wc -l`
echo 'B Queenside: ' `cat Bqueenside.pgn | wc -l`
echo 'Neither: ' `cat nocastle.pgn | wc -l`
echo 'Rights retained: ' `cat rights.txt | wc -l`

I tried the script on the KingBase database (Apr 2019) and, after removing broken games and duplicates got the following stats:
Number of games:  2072354
W Kingside:  1633762
W Queenside:  246158
B Kingside:  1670870
B Queenside:  128124
Neither:  69776
Rights retained:  24280

The 'neither' figure is about 3.4% while the 'rights retained' figure is about 1.2%. If games with 20 or fewer ply are removed then the 'neither' figure reduces to about 2.9% and the 'rights retained' figure to about 0.7%.

16626: <p>May I know how to find in all grandmaster games, what the percentage of each of the following is?</p>

<ul>
<li>Kingside castling</li>
<li>Queenside castling</li>
<li>Never castled by the end of the game but still has the right to castle</li>
<li>Lost the right to castle</li>
</ul>

<p><strong>Note</strong> When one side has <a href="http://www.chess-poster.com/english/mail/mail_2002/three_castlings.htm" rel="noreferrer">castled more than once in a game</a>, only the first castle counts.</p>
 7297: <p>Just googling for "castling statistics" already yields a few results; even though the analysis is done on a different set of games than 'all grandmaster games', it gives a rough indication.</p>

<ul>
<li><a href="https://www.reddit.com/r/chess/comments/a32glt/castling_statistics/" rel="noreferrer">50 world class players</a></li>
<li><a href="https://blog.ebemunk.com/a-visual-look-at-2-million-chess-games/" rel="noreferrer">2 million games in the MillionBase database</a></li>
</ul>

<p><strong>Kingside castling</strong> is done by 80-81% of the players, and <strong>queen side castling</strong> by 8-9%. I estimate that <strong>Never castled by the end of the game but still has the right to castle</strong> is negligible (less than 0.1%, since it requires a very short game). So that leaves about 11% for the final group <strong>Lost the right to castle</strong>.</p>
 12951: <p>If you are prepared to use standard Linux command-line tools like <code>wc</code> and <code>grep</code> then I think my free PGN processor, <a href="https://www.cs.kent.ac.uk/~djb/pgn-extract/" rel="noreferrer">pgn-extract</a>, will do much of the pre-processing necessary to count games in each category. Below is a basic bash script I put together as a proof of concept. It assumes your file of games is called <code>inputfile.pgn</code> - adjust as necessary, or pass it in as a command-line argument:</p>

<pre><code>#!/bin/bash
# Output stats on castling.
src=inputfile.pgn
# Pre-process the games to allow textual analysis.
pgn-extract -C -V -N --notags --nochecks --linelength 10000 -s -o stripped.pgn ${src}
# Castling by white: detect a preceding move number.
grep '\. O-O ' stripped.pgn &gt; Wkingside.pgn
grep '\. O-O-O ' stripped.pgn &gt; Wqueenside.pgn
# Castling by black: detect no preceding move number.
grep '[^.] O-O ' stripped.pgn &gt; Bkingside.pgn
grep '[^.] O-O-O ' stripped.pgn &gt; Bqueenside.pgn
# Find games in which no castling occurred.
grep -v ' O-O ' stripped.pgn | grep -v ' O-O-O ' | grep -v '^$' &gt; nocastle.pgn

# Output the FEN of the final position to include castling rights and
# look for the presence of rights.
pgn-extract -C -V -N --notags --nomovenumbers --linelength 10000 -s nocastle.pgn --dropply -1 -F | grep ' [wb] [KkQq]' &gt; rights.txt

# Output the results - assumes valid Result tags in the source.
echo 'Number of games: ' `grep '^\[Result ' ${src} | wc -l`
echo 'W Kingside: ' `cat Wkingside.pgn | wc -l`
echo 'W Queenside: ' `cat Wqueenside.pgn | wc -l`
echo 'B Kingside: ' `cat Bkingside.pgn | wc -l`
echo 'B Queenside: ' `cat Bqueenside.pgn | wc -l`
echo 'Neither: ' `cat nocastle.pgn | wc -l`
echo 'Rights retained: ' `cat rights.txt | wc -l`
</code></pre>

<p>I tried the script on the <a href="https://www.kingbase-chess.net/" rel="noreferrer">KingBase database</a> (Apr 2019) and, after removing broken games and duplicates got the following stats:</p>

<pre><code>Number of games:  2072354
W Kingside:  1633762
W Queenside:  246158
B Kingside:  1670870
B Queenside:  128124
Neither:  69776
Rights retained:  24280
</code></pre>

<p>The 'neither' figure is about 3.4% while the 'rights retained' figure is about 1.2%. If games with 20 or fewer ply are removed then the 'neither' figure reduces to about 2.9% and the 'rights retained' figure to about 0.7%.</p>
