# Can I use variables as entry key in bib files?

I would like to write something like

@string { subtype = "the-subtype" }

@string { entry = "the-entry1" }
@book{entry,
entrysubtype  = subtype,
file          = subtype # "/" # entry # ".pdf",
title         = {Title}type" }

@string { entry = "the-entry2" }
@book{entry,
entrysubtype  = subtype,
file          = subtype # "/" # entry # ".pdf",
title         = {Title}


In my experience it looks like I can use variables to set value of tags but it don't work for entry key.

Can I use variables as entry key in bib files?

That won't work. The entry key is special and not a normal <field> = {<value>}, pair as all other fields, where @strings work. In particular the entry key has a slightly different 'value' syntax than the fields, which makes it impossible to tell whether one wants the text as written or a @string replacement. Normally BibTeX knows that you want the @string because there are no braces around a @string

title  = {Lorem ipsum}, % normal value
author = sigfridsson,   % @string


We can't do the same with the entry key because it is always given as

@<type>{key,
...
}


without braces.

I also doubt that it is a good idea to have several @strings with the same identifier (@string {entry = ...}).

As in your previous question How to magically add the file field to each entry in a bib file? I would suggest a source map to produce the file field on the fly from information in the entrykey and entrysubtype fields. I don't quite know what you are after in your real-world application, but certainly for the example that seems to be much, much cleaner than repeating the same file = subtype # "/" # entry # ".pdf", sequence in each entry and overwriting the relevant @strings each time.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}

\DeclareSourcemap{
\maps[datatype=bibtex,overwrite=true]{
\map{
\step[fieldsource=entrysubtype, final]
\step[fieldset=file, origfieldval]
\step[fieldset=file, fieldvalue={/}, append]
\step[fieldsource=entrykey, final]
\step[fieldset=file, origfieldval, append]
\step[fieldset=file, fieldvalue={.pdf}, append]
}
}
}

% just to print the 'file' field
\DeclareFieldFormat{file}{file: \path{#1}}
\renewbibmacro{finentry}{\printfield{file}\finentry}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@string{subtype = "the-subtype" }

@book{the-entry1,
entrysubtype  = subtype,
title         = {Title},
}

@book{the-entry2,
entrysubtype  = subtype,
title         = {Title}
}
\end{filecontents}


Alternatively, you can still build the contents of the field directly within biblatex without the sourcemap, though that becomes more fiddly when you want to combine several field values into one string.